2014-09-18 23:10 GMT+08:00 Xiangrong Fang <xrf...@gmail.com>: > > I suspect that it is blocked on the RTLeventWaitFor, because if I use this: > > RTLeventWaitFor(Barrier, 1000); > > It will periodically pause for 1 second, then continue. >
I found the problem myself. Instead of writing: while not Terminated do begin RTLeventWaitFor(Barrier); if not IsPrime then Number := 0; Application.QueueAsyncCall(@AddPrime, PtrInt(Self)); RTLeventResetEvent(Barrier); end; I should write: while not Terminated do begin RTLeventWaitFor(Barrier); RTLeventResetEvent(Barrier); if not IsPrime then Number := 0; Application.QueueAsyncCall(@AddPrime, PtrInt(Self)); end; Because when doing the AsyncCall, the main thread may have called RTLeventSetEvent BEFORE the RTLeventResetEvent() is called. Xiangrong
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal