2014-09-18 16:13 GMT+08:00 Michael Schnell <mschn...@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​
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to