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

Comparing Coro/Coro.pm (file contents):
Revision 1.337 by root, Sun Oct 4 13:10:22 2015 UTC vs.
Revision 1.346 by root, Fri Jul 14 23:20:07 2017 UTC

366 366
367our $idle; # idle handler 367our $idle; # idle handler
368our $main; # main coro 368our $main; # main coro
369our $current; # current coro 369our $current; # current coro
370 370
371our $VERSION = 6.48; 371our $VERSION = 6.513;
372 372
373our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait); 373our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait);
374our %EXPORT_TAGS = ( 374our %EXPORT_TAGS = (
375 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 375 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
376); 376);
498C<async> does. As the coro is being reused, stuff like C<on_destroy> 498C<async> does. As the coro is being reused, stuff like C<on_destroy>
499will not work in the expected way, unless you call terminate or cancel, 499will not work in the expected way, unless you call terminate or cancel,
500which somehow defeats the purpose of pooling (but is fine in the 500which somehow defeats the purpose of pooling (but is fine in the
501exceptional case). 501exceptional case).
502 502
503The priority will be reset to C<0> after each run, tracing will be 503The priority will be reset to C<0> after each run, all C<swap_sv> calls
504disabled, the description will be reset and the default output filehandle 504will be undone, tracing will be disabled, the description will be reset
505gets restored, so you can change all these. Otherwise the coro will 505and the default output filehandle gets restored, so you can change all
506be re-used "as-is": most notably if you change other per-coro global 506these. Otherwise the coro will be re-used "as-is": most notably if you
507stuff such as C<$/> you I<must needs> revert that change, which is most 507change other per-coro global stuff such as C<$/> you I<must needs> revert
508simply done by using local as in: C<< local $/ >>. 508that change, which is most simply done by using local as in: C<< local $/
509>>.
509 510
510The idle pool size is limited to C<8> idle coros (this can be 511The idle pool size is limited to C<8> idle coros (this can be
511adjusted by changing $Coro::POOL_SIZE), but there can be as many non-idle 512adjusted by changing $Coro::POOL_SIZE), but there can be as many non-idle
512coros as required. 513coros as required.
513 514
637 # at this place, the timezone is Antarctica/South_Pole, 638 # at this place, the timezone is Antarctica/South_Pole,
638 # without disturbing the TZ of any other coro. 639 # without disturbing the TZ of any other coro.
639 }; 640 };
640 641
641This can be used to localise about any resource (locale, uid, current 642This can be used to localise about any resource (locale, uid, current
642working directory etc.) to a block, despite the existance of other 643working directory etc.) to a block, despite the existence of other
643coros. 644coros.
644 645
645Another interesting example implements time-sliced multitasking using 646Another interesting example implements time-sliced multitasking using
646interval timers (this could obviously be optimised, but does the job): 647interval timers (this could obviously be optimised, but does the job):
647 648
753=item $state->is_new 754=item $state->is_new
754 755
755Returns true iff this Coro object is "new", i.e. has never been run 756Returns true iff this Coro object is "new", i.e. has never been run
756yet. Those states basically consist of only the code reference to call and 757yet. Those states basically consist of only the code reference to call and
757the arguments, but consumes very little other resources. New states will 758the arguments, but consumes very little other resources. New states will
758automatically get assigned a perl interpreter when they are transfered to. 759automatically get assigned a perl interpreter when they are transferred to.
759 760
760=item $state->is_zombie 761=item $state->is_zombie
761 762
762Returns true iff the Coro object has been cancelled, i.e. 763Returns true iff the Coro object has been cancelled, i.e.
763it's resources freed because they were C<cancel>'ed, C<terminate>'d, 764it's resources freed because they were C<cancel>'ed, C<terminate>'d,
1122It is very common for a coro to wait for some callback to be 1123It is very common for a coro to wait for some callback to be
1123called. This occurs naturally when you use coro in an otherwise 1124called. This occurs naturally when you use coro in an otherwise
1124event-based program, or when you use event-based libraries. 1125event-based program, or when you use event-based libraries.
1125 1126
1126These typically register a callback for some event, and call that callback 1127These typically register a callback for some event, and call that callback
1127when the event occured. In a coro, however, you typically want to 1128when the event occurred. In a coro, however, you typically want to
1128just wait for the event, simplyifying things. 1129just wait for the event, simplyifying things.
1129 1130
1130For example C<< AnyEvent->child >> registers a callback to be called when 1131For example C<< AnyEvent->child >> registers a callback to be called when
1131a specific child has exited: 1132a specific child has exited:
1132 1133
1261processes. What makes it so bad is that on non-windows platforms, you can 1262processes. What makes it so bad is that on non-windows platforms, you can
1262actually take advantage of custom hardware for this purpose (as evidenced 1263actually take advantage of custom hardware for this purpose (as evidenced
1263by the forks module, which gives you the (i-) threads API, just much 1264by the forks module, which gives you the (i-) threads API, just much
1264faster). 1265faster).
1265 1266
1266Sharing data is in the i-threads model is done by transfering data 1267Sharing data is in the i-threads model is done by transferring data
1267structures between threads using copying semantics, which is very slow - 1268structures between threads using copying semantics, which is very slow -
1268shared data simply does not exist. Benchmarks using i-threads which are 1269shared data simply does not exist. Benchmarks using i-threads which are
1269communication-intensive show extremely bad behaviour with i-threads (in 1270communication-intensive show extremely bad behaviour with i-threads (in
1270fact, so bad that Coro, which cannot take direct advantage of multiple 1271fact, so bad that Coro, which cannot take direct advantage of multiple
1271CPUs, is often orders of magnitude faster because it shares data using 1272CPUs, is often orders of magnitude faster because it shares data using

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines