[fpc-pascal] Use sleep in thread

Xiangrong Fang xrfang at gmail.com
Wed Feb 25 16:05:08 CET 2015

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150225/bda1c845/attachment.html>

More information about the fpc-pascal mailing list