Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created August 18, 2017 12: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 jnthn/270633f76db049a52999cdb63a00df27 to your computer and use it in GitHub Desktop.
Save jnthn/270633f76db049a52999cdb63a00df27 to your computer and use it in GitHub Desktop.
my class Node {
has $.value;
has $.next;
}
for 1..4 -> $attempt {
my $head = Node;
await start {
for 1..10000 -> $i {
loop {
my $orig = $head;
my $next = Node.new(value => $i, next => $orig);
last if cas($head, $orig, $next) === $orig;
}
}
} xx 4;
my $total = 0;
my $cur = $head;
while $cur {
$total += $cur.value;
$cur = $cur.next;
}
say $total == 4 * [+](1..10000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment