Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Last active August 29, 2015 14:14
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 ab5tract/34408eaa7b5c64dc84a7 to your computer and use it in GitHub Desktop.
Save ab5tract/34408eaa7b5c64dc84a7 to your computer and use it in GitHub Desktop.
High Level Locked Counter
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