<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 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.  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.  The main thread, in its message handler then know from a status variable that this thread is in suspended status, then assign a new work to it and call its Execute() method again.</div><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, and can be reused by calling execute() again, right?</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">Even this works, if it is performance-wise not optimal, please give me a short example of how to use CriticalSection for this purpose.</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">Thanks a lot.</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">Xiangrong </div></div></div></div>