Our example demonstrates the concept of lightweight threads of execution called goroutines. Here’s the original source code:
Let’s convert this example to Pascal, a language with a similar concept for concurrent execution using threads:
To run the program, save the code in a file named GoroutinesExample.pas and use a Pascal compiler like Free Pascal to compile and run it.
When we run this Pascal program, we see the output of the blocking call first, then the output of the two threads. The thread outputs may be interleaved, as threads are running concurrently.
Next, we’ll look at a complement to goroutines in concurrent programs: channels (though not natively available in Pascal, equivalent synchronization techniques can be explored).