Skip to content

Instantly share code, notes, and snippets.

@smls
Last active October 14, 2017 10:36
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 smls/dbbc512df13d1bbe9836a53eb3e187f5 to your computer and use it in GitHub Desktop.
Save smls/dbbc512df13d1bbe9836a53eb3e187f5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
use v6.c;
my $lock = Lock.new;
my $current-action;
sub atomic-action ($id) {
$lock.protect: {
$current-action = $id;
sleep rand / 1000;
die "\$current-action should be '$id' but is '$_'"
if $_ ne $id given $current-action<>;
}
Nil
}
class A {
submethod DESTROY { atomic-action "DESTROY" };
}
await ^1000 .map: {
start {
A.new;
atomic-action "foo";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment