On 09/18/2014 01:46 PM, Xiangrong Fang wrote:
2014-09-18 19:34 GMT+08:00 Michael Schnell <mschn...@lumino.de <mailto:mschn...@lumino.de>>:


    I think, in the other mail, I did explain how "Wait" is supposed
    to work in TThreadPool.


Initially, when the threadpool is created, Wait is hold by the main thread, so the worker just wait there, no problem, but after the worker thread get the CS, it started working, then RELEASE the CS.

This is when the problem arise: after worker release the CS, how do you ensure it is the MAIN thread who will get the CS next, NOT the worker thread again?

The Thread uses "synchronize(NotifyStopped)" to call a procedure that is run in the main thread (and it waits until this procedure is done). In this synchronized procedure, the main thread Acquires "wait" again, and hence the worker thread will block at the start of the next main loop turn.

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

Reply via email to