Cooperative Threading in a Preemptive Environment

Top  Previous  Next

 

One of the advantages of Clarion 6 is that it is still possible to create an application that emulates the behavior associated with cooperative threading. Clarion 6 provides the necessary hooks so that you can decide whether your threads are preemptive, cooperative, or a mixture of the two. This topic introduces the concept and provides code samples.

 

Cooperative Threading Extension templates

All applications created prior to Clarion 6 had all threads other than the first one work in a cooperative manner. All new applications, and applications migrated to Clarion 6 will, by default, generate fully preemptive thread based applications.

If you decide to emulate the cooperative thread system, you will still have to convert some code affected by the change in the underlying thread and memory management model (see the Multi-Threaded Programming PDF).

If you use the Global Cooperative Threading extension template you are not limited to only have cooperative threads. You can have some or all threads preemptive. To make a procedure thread preemptive you need to activate the "Preemptive Procedure" procedure extension.

If your application is generated with preemptive threads, you can still make individual threads co-operative by adding the Global Cooperative Threading extension and turning off the cooperative option. Then, on each "Preemptive Procedure" procedure extension, turn off the preemptive feature to make the target procedure thread cooperative.