[Lazarus] PostMessage return value

Xiangrong Fang xrfang at gmail.com
Thu Sep 18 13:06:24 CEST 2014


2014-09-18 17:55 GMT+08:00 Michael Schnell <mschnell at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140918/1580228a/attachment-0003.html>


More information about the Lazarus mailing list