Skip to content

Instantly share code, notes, and snippets.

@AlexDaniel
Last active May 29, 2016 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDaniel/93949b15cfea51b9c9193ff248fe0286 to your computer and use it in GitHub Desktop.
Save AlexDaniel/93949b15cfea51b9c9193ff248fe0286 to your computer and use it in GitHub Desktop.
Lock example
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