<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 03:57 PM, Xiangrong Fang
wrote:<br>
</div>
<blockquote
cite="mid:CAP93jB23n_iJ1pg6R=mr7bvSZhX3MN0cinFAkk2iv8zA8xv=JQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-family:courier
new,monospace"><span style="font-family:arial">2014-09-15
21:44 GMT+08:00 Michael Schnell </span><span dir="ltr"
style="font-family:arial"><<a moz-do-not-send="true"
href="mailto:mschnell@lumino.de" target="_blank">mschnell@lumino.de</a>></span><span
style="font-family:arial">:</span><br>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span class="">
<div><br>
</div>
</span> 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.</div>
</blockquote>
<div><br>
</div>
<div class="gmail_default" style="font-family:'courier
new',monospace">That's exactly what I planed to do. But I
don't know "CriticalSections" can be used in here. </div>
</div>
</div>
</div>
</blockquote>
Why not (of course there might be alternatives). <br>
<blockquote
cite="mid:CAP93jB23n_iJ1pg6R=mr7bvSZhX3MN0cinFAkk2iv8zA8xv=JQ@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"> My original thinking is that, by the end
of Execute, I call either PostMessage or QueueAsyncCall to
notify main thread that the current thread finished its
work. <br>
</div>
</div>
</div>
</div>
</blockquote>
OK. Moreover TThread.Queue and TThread.Synchronize will work.<br>
<blockquote
cite="mid:CAP93jB23n_iJ1pg6R=mr7bvSZhX3MN0cinFAkk2iv8zA8xv=JQ@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">The main thread, in its message handler </div>
</div>
</div>
</div>
</blockquote>
(This is the procedure given in Application.QueueAsyncCall,
TThread.Queue and TThread.Synchronize) <br>
<blockquote
cite="mid:CAP93jB23n_iJ1pg6R=mr7bvSZhX3MN0cinFAkk2iv8zA8xv=JQ@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">then know from a status variable that this
thread is in suspended status,</div>
</div>
</div>
</div>
</blockquote>
OK, suspend will work similar to TCrtiticalSection. But for me
Suspend is a bit suspicious, as there is no direct Linux and
Information-Science equivalent to same (while TCriticalSection
directly maps to a Semaphore).<br>
<blockquote
cite="mid:CAP93jB23n_iJ1pg6R=mr7bvSZhX3MN0cinFAkk2iv8zA8xv=JQ@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"> then assign a new work to it and call its
Execute() method again.</div>
</div>
</div>
</div>
</blockquote>
I don't know how to " call its Execute()". I feel that you can't
leave the Execute procedures without killing the thread. So you need
to call the work-procedure from the execute procedure. <br>
<blockquote
cite="mid:CAP93jB23n_iJ1pg6R=mr7bvSZhX3MN0cinFAkk2iv8zA8xv=JQ@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">Is that ok? To be exact, when a thread's
execute() finished, it will go to a "sleep" status, </div>
</div>
</div>
</div>
</blockquote>
No. It will die.<br>
<blockquote
cite="mid:CAP93jB23n_iJ1pg6R=mr7bvSZhX3MN0cinFAkk2iv8zA8xv=JQ@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">and can be reused by calling execute()
again, right?</div>
</div>
</div>
</div>
</blockquote>
AFAIK: No. <br>
<br>
-Michael<br>
</body>
</html>