NAME
Thread::Stack - thread-safe stacks adapted from Thread::Queue
SYNOPSIS
use Thread::Stack;
my $s = new Thread::Stack;
$s->push("foo", "bar");
my $bar = $s->pop; # The "foo" is still in the stack.
my $foo = $s->pop_nb; # returns "foo", or undef if the stack was empty
my $size = $s->size; # returns the number of items still in the stack
DESCRIPTION
A stack, as implemented by Thread::Stack is a thread-safe data structure much like a list. Any number of threads can safely add or remove elements to or from the beginning of the list. (Stacks don't permit adding or removing elements from the middle of the list).
FUNCTIONS AND METHODS
- new
-
The
newfunction creates a new empty stack. - push LIST
-
The
pushmethod adds a list of scalars on the top of the stack. The stack will grow as needed to accommodate the list. - pop
-
The
popmethod removes a scalar from the top of the stack and returns it. If the stack is currently empty,popwill block the thread until another threadpushes a scalar. - pop_nb
-
The
pop_nbmethod, like thepopmethod, removes a scalar from the top of the stack and returns it. Unlikepop, though,pop_nbwon't block if the stack is empty, instead returningundef. - size
-
The
sizemethod returns the number of items still in the stack.
CREDIT
The author of Thread::Queue deserves any credit here. I simply modified Thread::Queue to implemnet a stack interface.