NAME

Thread::State - check threads' state

SYNOPSIS

use threads;
use Thread::State;

my $thr  = threads->new(sub { ... });

while ( $thr->is_running ) {
  ...
}

if( $thr->in_context ){ # = wantarray
    ...
}

if ($thr->is_joined) {
  ...
}

print threads->is_detached; # main thread is detached.

DESCRIPTION

This module adds some methods to threads which are used to check threads' state (is detached? joined? finished?) and created context.

Thread::Running is also for the same aim. It hacks threads::new, threads::join, and threads::detach. On the other hand, Thread::State peeks at the ithread structures directly.

You must use threads before using Thread::State.

METHODS

All below methods can be used as class methods. In that case, they return a current thread's state.

is_running

The thread is not finished.

is_finished

The thread is finished.

is_joined

The thread is joined.

is_detached

The thread is detached.

is_joinable

The thread is joinable (not joined, not detached).

in_context

Returns the created context of the thread. As like wantarray, if void context, returns undef, list context is true value, and scalar context is false.

coderef

Returns the thread coderef which was passed into create or new. When a thread code is finished with threads core version, the coderef refcount is made to 0 and destroyed. In that case coderef method will return undef.

NOTE

With Perl 5.8.0 on Windows, is_joined and is_joinable may not work correctly. This is the problem of threads itself.

This problem was fixed by Thread::State 0.04.

SEE ALSO

Thread::Running, threads

AUTHOR

Makamaka Hannyaharamitu, <makamaka[at]donzoko.net>

COPYRIGHT AND LICENSE

Copyright 2006 by Makamaka Hannyaharamitu

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.