Launching a thread - behind the scenes

Top  Previous  Next

With the advent of two new language statements supporting thread management in Clarion 6 (SUSPEND and RESUME), it is important to understand that there are a few things that are initialized and executed behind the scenes by the runtime library each time a thread is STARTed.

Here is the sequence of actions performed by the launching thread and the runtime library(RTL) each time a thread is STARTed:



Launching Thread executes START(ThreadProc)


RTL creates the physical thread in suspended state.


RTL resumes the launched thread created in step 2.


RTL sets an internal semaphore to a nonsignaled state.


Launching Thread waits for the semaphore from the RTL.


RTL creates instances of threaded variables and calls initialization routines for them.


RTL sets the semaphore to signaled state.


RTL suspends the launched thread creates in step 2.


Launching Thread continues program execution.


The launching thread will continue until it encounters the ACCEPT statement. Upon execution of the ACCEPT statement:


RTL resumes the launched thread.


RTL calls the entry point of the ThreadProc.


Therefore, a launched thread will remain suspended until the next call to ACCEPT from the launching thread. Only initialization and constructors for threaded variables are executed.


The use of RESUME with the START statement immediately executes Step 10 above without waiting for the call to ACCEPT. In other words, use of RESUME with START does not depend on the ACCEPT statement for resuming thread execution. This allows a new thread to be started from windowless threads.


The same can be said by using the SUSPEND statement immediately after START, e.g., SUSPEND immediately stops thread execution and does not wait for the ACCEPT loop.