[fpc-pascal] Random thread lockup. QueueAsyncCall??

Xiangrong Fang xrfang at gmail.com
Thu Sep 18 17:27:32 CEST 2014


2014-09-18 23:10 GMT+08:00 Xiangrong Fang <xrfang at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140918/19cf9ab6/attachment.html>


More information about the fpc-pascal mailing list