Course of Raku / Functional, concurrent, reactive, and web programming / Concurrent programming / Threads / Exercises / Run in a thread

Solution: Run in a thread

Here is a possible solution to the task.

Code

my $t = Thread.start({ say 'working' });
$t.finish;

🦋 You can find the source code in the file run-in-thread.raku.

Output

working

Comments

  1. Thread.start runs the block on a new thread.

  2. .finish waits for the thread to complete, so the program does not end before 42 is printed.

Course navigation

Run in a thread   |   Join and wait