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 new function creates a new empty stack.

push LIST

The push method adds a list of scalars on the top of the stack. The stack will grow as needed to accommodate the list.

pop

The pop method removes a scalar from the top of the stack and returns it. If the stack is currently empty, pop will block the thread until another thread pushes a scalar.

pop_nb

The pop_nb method, like the pop method, removes a scalar from the top of the stack and returns it. Unlike pop, though, pop_nb won't block if the stack is empty, instead returning undef.

size

The size method 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.

SEE ALSO

threads, threads::shared, Thread::Queue