On 09/18/2014 10:32 AM, Xiangrong Fang wrote:

Yesterday I read your ThreadPool source code, and cannot understand how you control which thread can get the "Wait" CS, rather than just let the 2 thread compete for it. Could you please explain the logic behind this?


Each worker Thread (i.e. the TThreadPoolThread instance) has it's own "Wait" semaphore (TCriticalSection instance).

The semaphore is owned by the main thread while the worker thread is supposed to do hold off, waiting to be assigned any work by setting the appropriate element of the "Tasks" property.

The semaphore is owned by the worker thread when it is working (as easily seen in the Execute procedure.

-Michael


--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to