Parallel programming with ContRap
The possibility of executing ContRap commands in parallel depends on the thread safety of the plugins. Most of the ContRap core components are thread safe. In this short tutorial it will be explained how call ContRap functions in parallel.
The "system" library contains the neccessary functions to use threading within the user-level.
["setStrict","isStrict","libraries","sleep","thread","concurrent","parallel","copy"]
To start a thread which executes a command the "thread" function is called with the command quoted:
The "thread" command is non-blocking. The command does not return a value, because at the return time point the thread is typically not yet ready with the execution. Use the assignment operator to get the execution result:
Usually, the user wants to let several threads work in parallel to compute parts of a complex problem. Then the user typically has to wait for all threads to stop before he can continue processing the results. This is done by calling the "parallel" command, which takes a list of commands to execute in parallel and waits for all created threads to return.
If the task is to run two different algorithms concurrently, the "concurrent" command useful. It takes a list of commands as input and waits them as long as at least one of the commands returns from execution. There is a result, which is the output of the command which returns first.