2014-09-18 17:55 GMT+08:00 Michael Schnell <mschn...@lumino.de>: > > Sven made me know that by "event" you did not mean an object pascal > language "Event" (i.e. a callback), but a "TEvent instance". >
Sorry, I mean *neither*. I mean an RTLEvent. See this page: http://www.freepascal.org/docs-html/rtl/system/rtleventcreate.html What I need help to understand is, repeating my previous email: While using ACriticalSection.Acquire, two threads are COMPETING for a "token" to do certain task, hence you do not know WHICH thread eventually get that token, although statistically each thread have the same chance of getting the token in the long run. While calling RTLeventWaitFor(), the calling thread gives up chance to run, blocked until another thread calls RTLeventSetEvent() to notify it. If the above understanding is correct, then I believe only RTLEvent can "synchronize" threads, i.e., let them run in a *determined* order. While CriticalSection ONLY provide a way to protect a shared resource is not accessed simultaneously. Alternatively, I have another "design": procedure TMyThread.Execute; begin while not Terminated do begin if FCondition = true then begin //do the job... end; end; end; In the code above, I do not use event or critical section is it enough to let this thread wait there, without wasting cpu time, until FCondition is set (externally by the main thread)? Thanks! Xiangrong
-- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus