Yury Kotlyarov > Tie-Array-Atomic > Tie::Array::Atomic

Download:
Tie-Array-Atomic-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Tie::Array::Atomic - ties a Perl array to a static atomic lock-free C-array

SYNOPSIS ^

  # 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',
  };

DESCRIPTION ^

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.

Options

length

(required) :: The number of elements in the array.

type

(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

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)

Typical perl array ops are unavailable.

You cannot push, pop, shift, or unshift on these arrays.

You can't access indices beyond what you have allocated.

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.

Only integer values or short byte arrays are allowed.

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.

METHODS ^

add, sub, and, or, xor, nand

This methods returns the result of atomic operation for array element

Example:

  tied(@buffer)->add(5, 1); # atomic increment for $buffer[5]

AUTHOR ^

Yury Kotlyarov <yury@cpan.org>

SEE ALSO ^

Devel::Malloc Tie::Array::Pointer Tie::Array

syntax highlighting: