[Lazarus] Lazarus application crash. Is PostMessage thread safe?
Giuliano Colla
giuliano.colla at fastwebnet.it
Wed Feb 10 11:19:15 CET 2016
Il 10/02/2016 08:44, zeljko ha scritto:
> 1.Your ErrList access does not look thread safe.
It's a poor man's thread safe queue, implemented as a ring buffer, with
two indexes, ErrGet and ErrPut. It's fully safe, provided the buffer is
guaranteed not to overflow, and that ErrPut is updated only after the
buffer has been written. Only the sending thread writes the buffer and
ErrPut, while the receiving thread only writes ErrGet, and reads just
once ErrPut.
This mechanism has been tested by some billion messages passing in the
years through it, by Kylix applications running 7/7 24h/24h in several
hundreds locations.
It's not that there have been billions if errors:-) , but an identical
setup is used to update informations at a rate of 8/10 per second. Only,
in Kylix I couldn't use PostMessage, and it was processed in an OnIdle
handler.
> 2.You are casting postMessage param as integer, IMO it's wrong,
> shouldn't it be PtrInt or LPARAM ?
> PostMessage(Form1.Handle,LM_ERROR, LPARAM(ErrPut),0);
PostMessage param is not actually used.
> 3.Application.ProcessMessages probably recurse.
This I believe to be the problem. From the observations from Denis I
realized that my code isn't protected against recursion, but I believe
that Application.ProcessMessages should protect itself too, avoiding to
handle more than once the same message.
However thanks a lot,
Giuliano
More information about the Lazarus
mailing list