<br><br><div class="gmail_quote">On 4 October 2011 11:14, Michael Schnell <span dir="ltr"><<a href="mailto:mschnell@lumino.de">mschnell@lumino.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On 10/04/2011 11:37 AM, Frank Church wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
What is the purpose of the while not Terminated in a threads execute loop?<br>
If a thread is doing its own thing and knows when or not it has finished what is the purpose of the while not Terminated<br>
</blockquote></div>
In Lazarus (and Delphi), "Worker Threads" can't have an "Event Loop" and so "event driven programming" (using "On..." procedures for the user code) is not possible. That is why in a Thread the user needs to create the "Loop" himself. Such a Thread should always run to a stall in some blocking library functions, lest it will take 100 % CPU time.<div class="im">
<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
Is Terminated designed to be called by other procedures besides the thread itself? Can a thread be Terminated externally?<br>
This also seems to imply that if the code within the while not Terminated loop is a long running sequence a Termniate command will not be processed until control returns to the beginning of the loop<br>
</blockquote></div>
A thread should terminate itself by exiting the Execute procedure. If not "FreeOnTerminate" is set. after termination the main thread should free the TThread object.<div class="im"><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
Can a thread respond to a new Execute command while it already Executing? <br>
</blockquote></div>
No.<div class="im"><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Do threads have ways of being interrogated about their state while Executing?<br>
</blockquote></div>
There are lots of ways of doing inter-thread communication. Simplest: any (no "ThreadVar") variable can mutually be read and written. A good (portable) way of notifying the Main thread about a state change is "Application.QueueAsyncCall". "TThread.Synchronize" calls a main thread event while stalling the thread for some indefinite amount of time.<div class="im">
<br></div></blockquote><div><br>I am looking at Application.QueueAsyncCall and the only parameter it takes in addition to the method pointer is a PrtInt. That seems to limit the options passed compared with TThread.Synchronize. Can the PtrInt be cast to a pointer to a richer data structure?<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
Suspend and Resume have been deprecated, and I want to know how a thread can be suspended.<br>
</blockquote></div>
Using Semaphores like "TCriticalSection".<div class="im"><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
If a thread is not set to FreeOnTerminate, can a thread suspend itself by using Terminate or some other custom function, doing some clean ups and waiting so it can be restarted by the Start procedure, by adding some custom fields to make it itself aware that it is an a paused state, so that when an Execute is sent it look up those fields, set Terminated to false and continue as though nothing has happened?<br>
<br>
</blockquote></div>
In certain applications (if it is not supposed to stall and wait) the main thread needs to check multiple times whether a TThread instance in fact is "Terminated" and thus can be freed.<br><font color="#888888">
<br>
-Michael</font><div><div></div><div class="h5"><br>
<br>
--<br>
______________________________<u></u>_________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org" target="_blank">Lazarus@lists.lazarus.<u></u>freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.<u></u>freepascal.org/mailman/<u></u>listinfo/lazarus</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Frank Church<br><br>=======================<br><a href="http://devblog.brahmancreations.com">http://devblog.brahmancreations.com</a><br>