Provides a thread-safe `compare_and_swap` primitive using C CAS intrinsics
use atomic;
my $a = \"abc";
atomic::compare_and_swap($a, $$a, "def");
is($$a, "def", "Same pointer, so it swaps");
atomic::compare_and_swap($a, "def", "ghi");
is($$a, "def", "Not the same pointer, so it doesn't swap");
Compares the value referred to by ref against $oldval. If the pointers match, replaces it with $newval.
This uses C CAS intrinsics and thus requires XS to glue C into perl.
It's possible to provide the same semantics using locks in pure perl but it will be slow!
Things are considered equal if the pointers match. Identically structured data are not equal.
This is a low-level library and you are expected to understand the implications of this.
Copyright (c) 2015 James Laver
Distributed under the same license terms as Perl itself.