Tie::Array::Atomic - ties a Perl array to a static atomic lock-free C-array
# 256 x (unsigned long) use Tie::Array::Atomic; my @buffer; tie @buffer, 'Tie::Array::Atomic', { length => 256, type => 'L', }; # 512 x (signed char) use Tie::Array::Atomic; my @buffer; tie @buffer, 'Tie::Array::Atomic', { length => 512, type => 'c', }; # 1024 x (char[5]); use Tie::Array::Atomic; my @buffer; tie @buffer, 'Tie::Array::Atomic', { length => 1024, type => 'a5', };
Tie::Array::Atomic ties a Perl array to static-sized C-array. Array stored in virtual memory and can be shared between threads. All operations for array elements are atomic, so no mutexes needed for array synchronization.
(required) :: The number of elements in the array.
(required) :: This is a very small subset of pack types, which defines whether the array contains 8 bit, 16 bit, 32 bit, 64 bit integers, or byte array up to 8 bytes. The valid values for this option
pack
are:
c signed char 8 bit C unsigned char 8 bit s signed short 16 bit S unsigned short 16 bit l signed long 32 bit L unsigned long 32 bit q signed quad 64 bit Q unsigned quad 64 bit a\d byte array \d bytes (ex. "a8" will 8 bytes array)
You cannot push, pop, shift, or unshift on these arrays.
push
pop
shift
unshift
You cannot access indices beyond the memory you have allocated. For example, consider the following code:
tie my @buffer, 'Tie::Array::Atomic', { length => 32, type => 's', }; $buffer[235355] = 5;
Here we allocated a 32 element array, but then we tried to assign something into the 235355th element of this array. THIS WILL SEGFAULT.
Please don't try to assign anything besides an integer or short byte arrays to an element. That means no floats and no references and no long strings.
This methods returns the result of atomic operation for array element
Example:
tied(@buffer)->add(5, 1); # atomic increment for $buffer[5]
Yury Kotlyarov <yury@cpan.org>
Devel::Malloc Tie::Array::Pointer Tie::Array
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head3'
To install Tie::Array::Atomic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Array::Atomic
CPAN shell
perl -MCPAN -e shell install Tie::Array::Atomic
For more information on module installation, please visit the detailed CPAN module installation guide.