--- Coro/Coro.pm 2008/09/08 21:49:45 1.197 +++ Coro/Coro.pm 2008/11/14 23:48:10 1.217 @@ -58,7 +58,7 @@ package Coro; -use strict; +use strict qw(vars subs); no warnings "uninitialized"; use Coro::State; @@ -69,7 +69,7 @@ our $main; # main coroutine our $current; # current coroutine -our $VERSION = 4.745; +our $VERSION = 5.0; our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); our %EXPORT_TAGS = ( @@ -154,7 +154,7 @@ # call all destruction callbacks $_->(@{$self->{_status}}) - for @{(delete $self->{_on_destroy}) || []}; + for @{ delete $self->{_on_destroy} || [] }; } # this coroutine is necessary because a coroutine @@ -170,7 +170,7 @@ &schedule; } }; -$manager->desc ("[coro manager]"); +$manager->{desc} = "[coro manager]"; $manager->prio (PRIO_MAX); =back @@ -223,7 +223,7 @@ or bad :). On the plus side, this function is faster than creating (and destroying) -a completely new coroutine, so if you need a lot of generic coroutines in +a completly new coroutine, so if you need a lot of generic coroutines in quick successsion, use C, not C. The code block is executed in an C context and a warning will be @@ -237,12 +237,12 @@ disabled, the description will be reset and the default output filehandle gets restored, so you can change all these. Otherwise the coroutine will be re-used "as-is": most notably if you change other per-coroutine global -stuff such as C<$/> you I to revert that change, which is most -simply done by using local as in: C< local $/ >. +stuff such as C<$/> you I revert that change, which is most +simply done by using local as in: C<< local $/ >>. -The pool size is limited to C<8> idle coroutines (this can be adjusted by -changing $Coro::POOL_SIZE), and there can be as many non-idle coros as -required. +The idle pool size is limited to C<8> idle coroutines (this can be +adjusted by changing $Coro::POOL_SIZE), but there can be as many non-idle +coros as required. If you are concerned about pooled coroutines growing a lot because a single C used a lot of stackspace you can e.g. Cthrow ([$scalar]) + +If C<$throw> is specified and defined, it will be thrown as an exception +inside the coroutine at the next convenient point in time (usually after +it gains control at the next schedule/transfer/cede). Otherwise clears the +exception object. + +The exception object will be thrown "as is" with the specified scalar in +C<$@>, i.e. if it is a string, no line number or newline will be appended +(unlike with C). + +This can be used as a softer means than C to ask a coroutine to +end itself, although there is no guarantee that the exception will lead to +termination, and if the exception isn't caught it might well end the whole +program. + +You might also think of C as being the moral equivalent of +Cing a coroutine with a signal (in this case, a scalar). + =item $coroutine->join Wait until the coroutine terminates and return any values given to the @@ -513,26 +532,11 @@ =item $olddesc = $coroutine->desc ($newdesc) Sets (or gets in case the argument is missing) the description for this -coroutine. This is just a free-form string you can associate with a coroutine. - -This method simply sets the C<< $coroutine->{desc} >> member to the given string. You -can modify this member directly if you wish. - -=item $coroutine->throw ([$scalar]) - -If C<$throw> is specified and defined, it will be thrown as an exception -inside the coroutine at the next convinient point in time (usually after -it gains control at the next schedule/transfer/cede). Otherwise clears the -exception object. - -The exception object will be thrown "as is" with the specified scalar in -C<$@>, i.e. if it is a string, no line number or newline will be appended -(unlike with C). +coroutine. This is just a free-form string you can associate with a +coroutine. -This can be used as a softer means than C to ask a coroutine to -end itself, although there is no guarentee that the exception will lead to -termination, and if the exception isn't caught it might well end the whole -program. +This method simply sets the C<< $coroutine->{desc} >> member to the given +string. You can modify this member directly if you wish. =cut @@ -644,7 +648,7 @@ schedule; # sleep well } }; -$unblock_scheduler->desc ("[unblock_sub scheduler]"); +$unblock_scheduler->{desc} = "[unblock_sub scheduler]"; sub unblock_sub(&) { my $cb = shift; @@ -663,11 +667,29 @@ =head1 BUGS/LIMITATIONS +=over 4 + +=item perl process emulation ("threads") + This module is not perl-pseudo-thread-safe. You should only ever use this module from the same thread (this requirement might be removed in the future to allow per-thread schedulers, but Coro::State does not yet allow -this). I recommend disabling thread support and using processes, as this -is much faster and uses less memory. +this). I recommend disabling thread support and using processes, as having +the windows process emulation enabled under unix roughly halves perl +performance, even when not used. + +=item coroutine switching not signal safe + +You must not switch to another coroutine from within a signal handler +(only relevant with %SIG - most event libraries provide safe signals). + +That means you I call any fucntion that might "block" the +current coroutine - C, C C<< Coro::Semaphore->down >> or +anything that calls those. Everything else, including calling C, +works. + +=back + =head1 SEE ALSO