Skip to content

perl-spark/atomic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

atomic

Provides a thread-safe `compare_and_swap` primitive using C CAS intrinsics

SYNOPSIS

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");

EXPORTS

compare_and_swap($ref, $oldval, $newval) -> Bool

Compares the value referred to by ref against $oldval. If the pointers match, replaces it with $newval.

GOTCHAS

XS

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!

POINTERS

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 AND LICENSE

Copyright (c) 2015 James Laver

Distributed under the same license terms as Perl itself.

About

Thread safe reference compare-and-set functionality

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages