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:

 

1.

Launching Thread executes START(ThreadProc)

2.

RTL creates the physical thread in suspended state.

3.

RTL resumes the launched thread created in step 2.

4.

RTL sets an internal semaphore to a nonsignaled state.

5.

Launching Thread waits for the semaphore from the RTL.

6.

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

7.

RTL sets the semaphore to signaled state.

8.

RTL suspends the launched thread creates in step 2.

9.

Launching Thread continues program execution.

 

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

10.

RTL resumes the launched thread.

11.

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.