-
-
Save smls/dbbc512df13d1bbe9836a53eb3e187f5 to your computer and use it in GitHub Desktop.
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
#!/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