September 2017
Beginner
402 pages
9h 52m
English
Perl 6 offers a mechanism of ensuring that a particular part of the code is executed by a single thread only. If there are other threads that would like to access the variables from this code, they should wait until it is unlocked.
To enclose the critical code, use the protect method of the Lock class. Examine the following example from the Perl 6 documentation:
my = 0;my = Lock.new;await (^10).map: say ; # OUTPUT: «10»
We will talk about the await function in the Factory methods section later in this chapter.
The critical code is protected in such a way that only one thread can access the $x counter at a time.
Locks are not recommended to be used directly, as they provide ...
Read now
Unlock full access