threads::tbb::concurrent::array - shared array variable via tbb::concurrent_vector
use threads::tbb; #my @array :concurrent; # TODO tie my @array, "threads::tbb::concurrent::array"; push @array, @items; # safe my $item = $array; # safe $array = $item; # safe # THREAD-UNSAFE but implemented: print $#array; $#array = 7; # never: $array->mutate;
The concurrent vector is an array that multiple threads can read to and write from. It also provides the advantage of using cache-aligned array slots, so threads don't conflict on nearby access with each other.
Implementation of basic array primitives is incomplete; stick with the concurrent API and you will be fine. Patches welcome!
The thread-safe operations on this type are (see perltie for specifics on the API of these methods):
Tied access to the array contents. If you are using index ranges from a threads::tbb::blocked_int, this is safe.
Tied access to pushing to the end of the array. Adding an item or list of items to the end of the list. There is no concurrent POP or SHIFT; see threads::tbb::concurrent::queue#TODO for that.
These functions return information which can get out of date. None of them are safe, because you'd need to hold an exclusive lock on the array to safely use them.
Get the length of the array.
Supported, calls grow_to_at_least and the grow_by. Does not permit shrinking the array.
Not implemented; so currently
@array = @foo doesn't work
Currently the TIEARRAY method doesn't respect tieing to an array with existing contents.