<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/18/2014 01:46 PM, Xiangrong Fang
wrote:<br>
</div>
<blockquote
cite="mid:CAP93jB2=_GzCs3uUM1hG-VApDzPcENZC1g9X8Q7qU6N+E-9weA@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-18
19:34 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">
<div><br>
</div>
I think, in the other mail, I did explain how "Wait" is
supposed to work in TThreadPool. <br>
<span class="HOEnZb"><font color="#888888"><br>
</font></span></div>
</blockquote>
<div><br>
</div>
<div class="gmail_default" style="font-family:'courier
new',monospace">Initially, when the threadpool is created,
Wait is hold by the main thread, so the worker just wait
there, no problem, but after the worker thread get the CS,
it started working, then RELEASE the CS.</div>
<div class="gmail_default" style="font-family:'courier
new',monospace"><br>
</div>
<div class="gmail_default" style="font-family:'courier
new',monospace">This is when the problem arise: after
worker release the CS, how do you ensure it is the MAIN
thread who will get the CS next, NOT the worker thread
again?</div>
<br>
</div>
</div>
</div>
</blockquote>
The Thread uses "synchronize(NotifyStopped)" to call a procedure
that is run in the main thread (and it waits until this procedure is
done). In this synchronized procedure, the main thread Acquires
"wait" again, and hence the worker thread will block at the start of
the next main loop turn. <br>
<br>
-Michael<br>
</body>
</html>