On 4 October 2011 10:43, <[email protected]> wrote: > > > On Tue, 4 Oct 2011, Frank Church wrote: > > What is the purpose of the while not Terminated in a threads execute loop? >> 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 >> >> Is Terminated designed to be called by other procedures besides the thread >> itself? Can a thread be Terminated externally? >> > > Yes. > > > 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 >> > > The Execute method is supposed to check Terminated at regular intervals. > > > >> Can a thread respond to a new Execute command while it already Executing? >> Do >> threads have ways of being interrogated about their state while Executing? >> > > No. It is an error to call execute twice. > > The only interrogation you can do is check for 'Terminated'. > > Isn't it possible to have add new fields to your thread that can be interrogated? e.g. another routine wants to call the thread's Execute method. Whenever the thread is executing it sets a field named FProcessing:= true, so the routing which wants to call the thread's execute method can read FProcessing and not call the execute until FProcessing is false. Is this possible?
> Suspend and Resume have been deprecated, and I want to know how a thread >> can >> be suspended. >> > > There is - to my knowledge - no safe way of doing so. > > > 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? >> > > Terminate should only be used to actually terminate the thread. > You can implement some custom commands to put them in a 'suspended' state, > if you want. (using mutexes, semaphores and whatnot) > > ie this means that a routine that wants to the thread to stop can call Terminate, but it is up to the Thread itself to respond, it can't be forced? > You should assume only that if Execute() exits, the thread will be > cleaned up. > > Michael. > > -- > ______________________________**_________________ > Lazarus mailing list > [email protected].**freepascal.org<[email protected]> > http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus> > -- Frank Church ======================= http://devblog.brahmancreations.com
-- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
