[Lazarus] PostMessage return value

Xiangrong Fang xrfang at gmail.com
Thu Sep 18 10:32:31 CEST 2014


2014-09-18 16:13 GMT+08:00 Michael Schnell <mschnell at lumino.de>:

>
> I did the TThreadPool class just for fun. I'll compare the two thingies
> and come back with some comments.
>
>
​I don't quite understand the logic or difference between critical section ​

​and events. My feeling is that to do synchronization you will have to use
event (I will do some test to verify that).  Because when you use critical
section, like in your ThreadPool:

procedure TThreadPoolThread.Execute;
begin
  while not Terminated do begin
    Wait.Aquire;
    ...
  end;
end;

You are actively try to aquire the CS.  i.e. After you finish this loop and
notify the main thread, how do you ensure which thread will get this CS
next? The main thread or this worker thread?

​But if you use something like this (I don't know if the syntax or usage is
correct, just show my thinking):

procedure TThreadPoolThread.Execute;
begin
  while not Terminated do begin
    RTLEventWaitFor(Wait);
    ...
  end;
end;
​
​Then, you are PASSIVELY wait for the event which will be set/reset from
OUTSIDE this working thread.

That's what confused me how can you use a CS for the purpose of thread
synchronization!

Yesterday I read your ThreadPool source code, and cannot understand how you
control which thread can get the "Wait" CS, rather than just let the 2
thread compete for it. Could you please explain the logic behind this?

Thanks!

Xiangrong​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140918/90b5486a/attachment-0003.html>


More information about the Lazarus mailing list