» Asynchronous Locking
Raku actually provides two different locking classes. A
Lock object provides a very standard
locking mechanism. When .lock and .unlock are used or .protect is called,
you get a section of code that pauses until the lock frees up, runs while
holding the lock, and then frees the lock so other code that might be waiting on
the lock can run.
However, the Lock class works in such a way that blocks the current thread. As
I’ve pointed out earlier in this advent calendar, the purpose of threads is to
do stuff, so blocking them from running is preventing them from fulfilling their
purpose. Luckily, there is a solution.