X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2Fthreads%2Fthreads.pm;h=dcd2aa015c9a65619b9fa687f4feb3ff04fdde7c;hb=8043fdafce9b64db18484779a548e4f4adefc5ed;hp=337aaf5027cf4c6a3e9db7ef753ea6dcce9a1340;hpb=88f8c1dfe3e63f5bedaea1d870d5c68b59613b12;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/threads/threads.pm b/ext/threads/threads.pm index 337aaf5..dcd2aa0 100755 --- a/ext/threads/threads.pm +++ b/ext/threads/threads.pm @@ -31,8 +31,6 @@ use overload '==' => \&equal, 'fallback' => 1; -#use threads::Shared; - BEGIN { warn "Warning, threads::shared has already been loaded. ". "To enable shared variables for these modules 'use threads' ". @@ -52,18 +50,15 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( async ); -our $VERSION = '0.99'; +our $VERSION = '1.05'; -sub equal { - return 1 if($_[0]->tid() == $_[1]->tid()); - return 0; -} +# || 0 to ensure compatibility with previous versions +sub equal { ($_[0]->tid == $_[1]->tid) || 0 } -sub async (&;@) { - my $cref = shift; - return threads->new($cref,@_); -} +# use "goto" trick to avoid pad problems from 5.8.1 (fixed in 5.8.2) +# should also be faster +sub async (&;@) { unshift @_,'threads'; goto &new } sub object { return undef unless @_ > 1; @@ -144,18 +139,26 @@ it the other way around. This will create a new thread with the entry point function and give it LIST as parameters. It will return the corresponding threads -object. The new() method is an alias for create(). +object, or C if thread creation failed. The new() method is an +alias for create(). =item $thread->join This will wait for the corresponding thread to join. When the thread finishes, join() will return the return values of the entry point function. If the thread has been detached, an error will be thrown. + +The context (scalar or list) of the thread creation is also the +context for join(). This means that if you intend to return an array +from a thread, you must use Cnew(...)>, and +that if you intend to return a scalar, you must use C. + If the program exits without all other threads having been either joined or detached, then a warning will be issued. (A program exits either because one of its threads explicitly calls exit(), or in the case of the main thread, reaches the end of the main program file.) + =item $thread->detach Will make the thread unjoinable, and cause any eventual return value @@ -267,13 +270,13 @@ signal handling is not threadsafe. =head1 AUTHOR and COPYRIGHT -Arthur Bergman Earthur at contiller.seE +Arthur Bergman Esky at nanisky.comE threads is released under the same license as Perl. Thanks to -Richard Soderberg Ers at crystalflame.netE +Richard Soderberg Eperl at crystalflame.netE Helping me out tons, trying to find reasons for races and other weird bugs! Simon Cozens Esimon at brecon.co.ukE