<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 09/15/2014 02:55 PM, Xiangrong Fang
wrote:<br>
</div>
<blockquote
cite="mid:CAP93jB1etQ23Og1ZkvLGDdAy2ua4KL779aE+5Qe4D8K=Vd-KDg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-family:courier
new,monospace"><br>
</div>
<div class="gmail_extra">
<div class="gmail_quote"><br>
<div class="gmail_default" style="font-family:'courier
new',monospace"><br>
</div>
<div class="gmail_default" style="font-family:'courier
new',monospace">How do I use Event to achieve the same? </div>
</div>
</div>
</div>
</blockquote>
What do you mean by "Event" ? <br>
<blockquote
cite="mid:CAP93jB1etQ23Og1ZkvLGDdAy2ua4KL779aE+5Qe4D8K=Vd-KDg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div class="gmail_default" style="font-family:'courier
new',monospace">It seems that I can have N threads
"listen" to the same event, but cannot have the main
thread to "listen" to N different events?</div>
</div>
</div>
</div>
</blockquote>
In fact Windows does provide event (aka "Message") queues for all
threads out of the boy, Linux does not provide any event queues. <br>
<br>
Lazarus (like Delphi) provides some support for an Event Queue for
the Main thread. Lazarus does this both in Windows and Linux (and
Mac OS). The queue can be fed by GUI events, (non-Delphi)
Application.QueueAsyncCall (and TThread.Synchronize and - with the
FPC svn version - TThread.Queue). <br>
<br>
There is no support by the language for Event Queues for worker
Threads. In Windows you could use messages directly by API calls, in
Linux you could use Pipes with the appropriate API calls like
"open", "select", "epoll", ...<br>
<br>
<br>
<blockquote
cite="mid:CAP93jB1etQ23Og1ZkvLGDdAy2ua4KL779aE+5Qe4D8K=Vd-KDg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div class="gmail_default" style="font-family:'courier
new',monospace"><br>
</div>
<div class="gmail_default" style="font-family:'courier
new',monospace"> For now, I would like to know,
performance-wise, which way is better? Using
QueueAsyncCall/PostMessage or RTLEvent*?</div>
</div>
</div>
</div>
</blockquote>
<br>
Performance wise it's better not to destroy and create your threads
but to manage a thread pool and assign work to the threads as
appropriate. <br>
<br>
Here you would have the threads wait for work e.g. by trapping
themselves in a TCriticalSection for each one. <br>
<br>
Now the Main thread can easily free a thread after it assigned work
to it (e.g. by providing a callback function that is to be called in
TThread.Execute). If work is done, the Thread could notify the
manager (in the main thread) by Application.QueueAsyncCall or
TThread.Queue. TThread. Synchronize would not harm in this case
either, as the thread at that time has nothing to do anyway.<br>
<br>
-Michael<br>
</body>
</html>