Thread::Exit

Thread::Exit is a Perl module to provide thread-local exit(), BEGIN {}, END {} and exited().
Download

Thread::Exit Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Elizabeth Mattijsen
  • Publisher web site:
  • http://search.cpan.org/~elizabeth/

Thread::Exit Tags


Thread::Exit Description

Thread::Exit is a Perl module to provide thread-local exit(), BEGIN {}, END {} and exited(). Thread::Exit is a Perl module to provide thread-local exit(), BEGIN {}, END {} and exited().SYNOPSIS use Thread::Exit (); # just make exit() thread local use Thread::Exit begin => 'begin_sub', # sub to exec at beginning of thread (default: none) end => 'end_sub', # sub to exec at end of thread (default: none) inherit => 1, # make all new threads inherit (default: 1) ; $thread = threads->new( sub { exit( "We've exited" ) } ); # or "create" print $thread->join; # prints "We've exited" Thread::Exit->ismain; # mark this thread as main thread Thread::Exit->begin( $begin_sub ); # set/adapt BEGIN sub later Thread::Exit->begin( undef ); # disable BEGIN sub $begin = Thread::Exit->begin; Thread::Exit->end( $end_sub ); # set/adapt END sub later Thread::Exit->end( undef ); # disable END sub $end = Thread::Exit->end; Thread::Exit->inherit( 1 ); # make all new threads inherit settings Thread::Exit->inherit( 0 ); # new threads won't inherit settings $inherit = Thread::Exit->inherit; *** A note of CAUTION *** This module only functions on Perl versions 5.8.0 and later. And then only when threads are enabled with -Dusethreads. It is of no use with any version of Perl before 5.8.0 or without threads enabled. *************************This module adds three features to threads that are sorely missed by some.The first feature is that you can use exit() within a thread to return() from that thread only. Without this module, exit() stops all threads and exits to the calling process (which usually is the operating system). With this module, exit() functions just as return() (including passing back values to the parent thread).The second feature is that you can specify a subroutine that will be executed after the thread is started, but before the subroutine of which the thread consists, is started. This is an alternate implementation of the CLONE subroutine, which differs by being really executed inside the context of the new thread (as shown by the value of threads-tid>). Multiple "begin" subroutines can be chained together if necessary.The third feature is that you can specify a subroutine that will be executed after the thread is done, but before the thread returns to the parent thread. This is similar to the END subroutine, but on a per-thread basis. Multiple "end" subroutines can be chained together if necessary. Requirements: · Perl


Thread::Exit Related Software