ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Coro/Coro.pm
(Generate patch)

Comparing cvsroot/Coro/Coro.pm (file contents):
Revision 1.249 by root, Mon Dec 15 15:21:25 2008 UTC vs.
Revision 1.253 by root, Fri May 29 07:01:18 2009 UTC

80 80
81our $idle; # idle handler 81our $idle; # idle handler
82our $main; # main coro 82our $main; # main coro
83our $current; # current coro 83our $current; # current coro
84 84
85our $VERSION = 5.13; 85our $VERSION = 5.132;
86 86
87our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); 87our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub);
88our %EXPORT_TAGS = ( 88our %EXPORT_TAGS = (
89 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 89 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
90); 90);
346 346
347These functions are best understood by an example: The following function 347These functions are best understood by an example: The following function
348will change the current timezone to "Antarctica/South_Pole", which 348will change the current timezone to "Antarctica/South_Pole", which
349requires a call to C<tzset>, but by using C<on_enter> and C<on_leave>, 349requires a call to C<tzset>, but by using C<on_enter> and C<on_leave>,
350which remember/change the current timezone and restore the previous 350which remember/change the current timezone and restore the previous
351value, respectively, the timezone is only changes for the coro that 351value, respectively, the timezone is only changed for the coro that
352installed those handlers. 352installed those handlers.
353 353
354 use POSIX qw(tzset); 354 use POSIX qw(tzset);
355 355
356 async { 356 async {
426the ready queue, do nothing and return false. 426the ready queue, do nothing and return false.
427 427
428This ensures that the scheduler will resume this coro automatically 428This ensures that the scheduler will resume this coro automatically
429once all the coro of higher priority and all coro of the same 429once all the coro of higher priority and all coro of the same
430priority that were put into the ready queue earlier have been resumed. 430priority that were put into the ready queue earlier have been resumed.
431
432=item $coro->suspend
433
434Suspends the specified coro. A suspended coro works just like any other
435coro, except that the scheduler will not select a suspended coro for
436execution.
437
438Suspending a coro can be useful when you want to keep the coro from
439running, but you don't want to destroy it, or when you want to temporarily
440freeze a coro (e.g. for debugging) to resume it later.
441
442A scenario for the former would be to suspend all (other) coros after a
443fork and keep them alive, so their destructors aren't called, but new
444coros can be created.
445
446=item $coro->resume
447
448If the specified coro was suspended, it will be resumed. Note that when
449the coro was in the ready queue when it was suspended, it might have been
450unreadied by the scheduler, so an activation might have been lost.
451
452To avoid this, it is best to put a suspended coro into the ready queue
453unconditionally, as every synchronisation mechanism must protect itself
454against spurious wakeups, and the one in the Coro family certainly do
455that.
431 456
432=item $is_ready = $coro->is_ready 457=item $is_ready = $coro->is_ready
433 458
434Returns true iff the Coro object is in the ready queue. Unless the Coro 459Returns true iff the Coro object is in the ready queue. Unless the Coro
435object gets destroyed, it will eventually be scheduled by the scheduler. 460object gets destroyed, it will eventually be scheduled by the scheduler.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines