Last active
August 29, 2015 14:14
-
-
Save ab5tract/34408eaa7b5c64dc84a7 to your computer and use it in GitHub Desktop.
High Level Locked Counter
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
use OO::Monitors; | |
monitor Increment { | |
has $.counter; | |
method increment( $thread ) { | |
$!counter++; | |
say "incremented in $thread"; | |
} | |
} | |
my $locker = Increment.new; | |
for ^100000 { | |
# using await works, probably because having two say calls occuring simultaneously can't happen? | |
# await start { | |
start { | |
say "\t gonna try to increment from $_ now"; | |
$locker.increment( $_ ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment