[fpc-pascal] Use sleep in thread

hinstance at yandex.ru hinstance at yandex.ru
Wed Feb 25 16:16:38 CET 2015


not sure if this helps, but:
for example, if you want thread T to run using approx. 70% of max. available capacity, try this:

repeat
  T.Resume;
  Sleep(70);
  T.Resume;
  Sleep(30);
until ...

so T runs for 70 ms, then sleeps for 30 ms, etc

25.02.2015, 18:06, "Xiangrong Fang" <xrfang at gmail.com>:
> 2015-02-25 22:47 GMT+08:00 Dmitry Boyarintsev <skalogryz.lists at gmail.com>:
>> I presume most of the systems would make the sleeping thread to yield the execution time for other threads.
>> The questionable behavior might occur in case of  sleep(0); (should it yield the remaining time or just return immediately - up to the OS).
>> And multi-cpu might also do something different.
> ​Yes, I am particularly interested in behavior of SMP system. i.e. my purpose of using threads is to take full advantages of all CPU cores.
>
> As far as I know, setting thread priority does not always work, it may require root privilege for example.  I would like to use Sleep() to control relative time share of all threads in the pool.  For example, I run 3 threads on a dual-core system, with thread 1 and 2 share core-1, and thread 3 taking all computing power of core-2...
>
> Now the problem is, can I use Sleep to control thread 1 to run at 50% of the speed of thread 2 (which is not throttled), providing that all threads are doing same kind of task, so that they are comparable?
>
> Xiangrong​
>
> ,
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list