-
-
Save AlexDaniel/93949b15cfea51b9c9193ff248fe0286 to your computer and use it in GitHub Desktop.
Lock example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $x = 0; await (^1000).map: { start { sleep 0.001; $x++ } }; | |
say $x; # 954 (different result every time) | |
my $y = 0; my $l = Lock.new; await (^1000).map: { start { $l.protect({ sleep 0.001; $y++ }) } }; | |
say $y; # 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment