Our example demonstrates the use of goroutines, a lightweight thread of execution. Here’s the full source code in Scilab.
Suppose we have a function call f(from). Here’s how we’d call that in the usual way, running it synchronously.
To invoke this function asynchronously in Scilab, we use a construct to simulate goroutines since Scilab does not have built-in support for concurrent execution. Here is how we can schedule these tasks:
Our two function calls are running asynchronously now. Wait for them to finish:
When we run this program, we see the output of the blocking call first, then the output of the two asynchronous tasks. The output may be interleaved because tasks are being run asynchronously.
Next, we’ll look at a complement to asynchronous tasks in concurrent programs: communication between tasks.