If not already thread-shared, the other complex data types will be cloned
(recursively, if needed, and including any blessings and read-only
settings) into thread-shared structures before being placed onto a queue.

For example, the following would cause Thread::Queue to create a empty,
shared array reference via &shared([])
, copy the elements 'foo', 'bar'
and 'baz' from @ary
into it, and then place that shared reference onto
the queue:

QUEUE CREATION

BASIC METHODS

The following methods deal with queues on a FIFO basis.

->enqueue(LIST)

Adds a list of items onto the end of the queue.

->dequeue()

->dequeue(COUNT)

Removes the requested number of items (default is 1) from the head of the
queue, and returns them. If the queue contains fewer than the requested
number of items, then the thread will be blocked until the requisite number
of items are available (i.e., until other threads <enqueue> more items).

->dequeue_nb()

->dequeue_nb(COUNT)

Removes the requested number of items (default is 1) from the head of the
queue, and returns them. If the queue contains fewer than the requested
number of items, then it immediately (i.e., non-blocking) returns whatever
items there are on the queue. If the queue is empty, then undef is
returned.

->pending()

Returns the number of items still in the queue.

ADVANCED METHODS

The following methods can be used to manipulate items anywhere in a queue.

To prevent the contents of a queue from being modified by another thread
while it is being examined and/or changed, lock the queue inside a local block:

Returns an item from the queue without dequeuing anything. Defaults to the
the head of queue (at index position 0) if no index is specified. Negative
index values are supported as with arrays (i.e., -1
is the end of the queue, -2 is next to last, and so on).

If no items exists at the specified index (i.e., the queue is empty, or the
index is beyond the number of items on the queue), then undef is returned.

Remember, the returned item is not removed from the queue, so manipulating a
peek
ed at reference affects the item on the queue.

->insert(INDEX, LIST)

Adds the list of items to the queue at the specified index position (0
is the head of the list). Any existing items at and beyond that position are
pushed back past the newly added items:

$q->enqueue(1,2,3,4);

$q->insert(1,qw/foo bar/);

# Queue now contains: 1, foo, bar, 2, 3, 4

Specifying an index position greater than the number of items in the queue
just adds the list to the end.

Negative index positions are supported:

$q->enqueue(1,2,3,4);

$q->insert(-2,qw/foo bar/);

# Queue now contains: 1, 2, foo, bar, 3, 4

Specifying a negative index position greater than the number of items in the
queue adds the list to the head of the queue.

->extract()

->extract(INDEX)

->extract(INDEX, COUNT)

Removes and returns the specified number of items (defaults to 1) from the
specified index position in the queue (0 is the head of the queue). When
called with no arguments, extract
operates the same as dequeue_nb
.

This method is non-blocking, and will return only as many items as are
available to fulfill the request:

Negative index positions are supported. Specifying a negative index position
greater than the number of items in the queue may return items from the head
of the queue (similar to dequeue_nb
) if the count overlaps the head of the
queue from the specified position (i.e. if queue size + index + count is
greater than zero):