Preemptive processes are very useful for performing extensive calculations in parallel, using all of the cores in your CPU, but sometimes you need to delegate tasks to a cooperative process (e.g., using a non-preemptive command). With the New signal command, you can pause a process and wait for the response from another process!
The New signal command creates a shared object and allows you to manage the interruption and continuity of the current process. Two methods are available for this:
- wait()
- trigger()
In the example below, we need to open a form from a preemptive process. Since the Open form window command isn’t preemptive, the main process is called to open the form, and the calling process is put on hold until the user enters a value.
First, write a method that calls the main process and wait for the result:
C_OBJECT($signal)
// Creation of a signal
$signal:=New signal
// call main process and execute OpenForm method
CALL WORKER(1;"OpenForm";$signal)
// do another calculation
...
// Waiting for the end of the process
$signaled:=$signal.wait()
// Calculate the results
$calc:=$signal.result+...
Then the OpenForm method will wake up the process with the trigger method:
C_OBJECT($1;$signal;$form)
$signal:=$1
$form:=New object("value";0)
// Open the form and ask the user for a value
$win:=Open form window("Information";Movable form dialog box)
DIALOG("Information";$form)
CLOSE WINDOW($win)
// Add a new attribute to $signal to pass result to other process
Use ($signal)
$signal.result:=$form.value
End use
// Trigger the signal for the waiting process
$signal.trigger()