… | |
… | |
366 | |
366 | |
367 | our $idle; # idle handler |
367 | our $idle; # idle handler |
368 | our $main; # main coro |
368 | our $main; # main coro |
369 | our $current; # current coro |
369 | our $current; # current coro |
370 | |
370 | |
371 | our $VERSION = 6.41; |
371 | our $VERSION = 6.511; |
372 | |
372 | |
373 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait); |
373 | our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub rouse_cb rouse_wait); |
374 | our %EXPORT_TAGS = ( |
374 | our %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 | ); |
… | |
… | |
498 | C<async> does. As the coro is being reused, stuff like C<on_destroy> |
498 | C<async> does. As the coro is being reused, stuff like C<on_destroy> |
499 | will not work in the expected way, unless you call terminate or cancel, |
499 | will not work in the expected way, unless you call terminate or cancel, |
500 | which somehow defeats the purpose of pooling (but is fine in the |
500 | which somehow defeats the purpose of pooling (but is fine in the |
501 | exceptional case). |
501 | exceptional case). |
502 | |
502 | |
503 | The priority will be reset to C<0> after each run, tracing will be |
503 | The priority will be reset to C<0> after each run, all C<swap_sv> calls |
504 | disabled, the description will be reset and the default output filehandle |
504 | will be undone, tracing will be disabled, the description will be reset |
505 | gets restored, so you can change all these. Otherwise the coro will |
505 | and the default output filehandle gets restored, so you can change all |
506 | be re-used "as-is": most notably if you change other per-coro global |
506 | these. Otherwise the coro will be re-used "as-is": most notably if you |
507 | stuff such as C<$/> you I<must needs> revert that change, which is most |
507 | change other per-coro global stuff such as C<$/> you I<must needs> revert |
508 | simply done by using local as in: C<< local $/ >>. |
508 | that change, which is most simply done by using local as in: C<< local $/ |
|
|
509 | >>. |
509 | |
510 | |
510 | The idle pool size is limited to C<8> idle coros (this can be |
511 | The idle pool size is limited to C<8> idle coros (this can be |
511 | adjusted by changing $Coro::POOL_SIZE), but there can be as many non-idle |
512 | adjusted by changing $Coro::POOL_SIZE), but there can be as many non-idle |
512 | coros as required. |
513 | coros 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 | |
641 | This can be used to localise about any resource (locale, uid, current |
642 | This can be used to localise about any resource (locale, uid, current |
642 | working directory etc.) to a block, despite the existance of other |
643 | working directory etc.) to a block, despite the existence of other |
643 | coros. |
644 | coros. |
644 | |
645 | |
645 | Another interesting example implements time-sliced multitasking using |
646 | Another interesting example implements time-sliced multitasking using |
646 | interval timers (this could obviously be optimised, but does the job): |
647 | interval timers (this could obviously be optimised, but does the job): |
647 | |
648 | |
… | |
… | |
753 | =item $state->is_new |
754 | =item $state->is_new |
754 | |
755 | |
755 | Returns true iff this Coro object is "new", i.e. has never been run |
756 | Returns true iff this Coro object is "new", i.e. has never been run |
756 | yet. Those states basically consist of only the code reference to call and |
757 | yet. Those states basically consist of only the code reference to call and |
757 | the arguments, but consumes very little other resources. New states will |
758 | the arguments, but consumes very little other resources. New states will |
758 | automatically get assigned a perl interpreter when they are transfered to. |
759 | automatically get assigned a perl interpreter when they are transferred to. |
759 | |
760 | |
760 | =item $state->is_zombie |
761 | =item $state->is_zombie |
761 | |
762 | |
762 | Returns true iff the Coro object has been cancelled, i.e. |
763 | Returns true iff the Coro object has been cancelled, i.e. |
763 | it's resources freed because they were C<cancel>'ed, C<terminate>'d, |
764 | it's resources freed because they were C<cancel>'ed, C<terminate>'d, |
… | |
… | |
1021 | otherwise you might suffer from crashes or worse. The only event library |
1022 | otherwise you might suffer from crashes or worse. The only event library |
1022 | currently known that is safe to use without C<unblock_sub> is L<EV> (but |
1023 | currently known that is safe to use without C<unblock_sub> is L<EV> (but |
1023 | you might still run into deadlocks if all event loops are blocked). |
1024 | you might still run into deadlocks if all event loops are blocked). |
1024 | |
1025 | |
1025 | Coro will try to catch you when you block in the event loop |
1026 | Coro will try to catch you when you block in the event loop |
1026 | ("FATAL:$Coro::IDLE blocked itself"), but this is just best effort and |
1027 | ("FATAL: $Coro::idle blocked itself"), but this is just best effort and |
1027 | only works when you do not run your own event loop. |
1028 | only works when you do not run your own event loop. |
1028 | |
1029 | |
1029 | This function allows your callbacks to block by executing them in another |
1030 | This function allows your callbacks to block by executing them in another |
1030 | coro where it is safe to block. One example where blocking is handy |
1031 | coro where it is safe to block. One example where blocking is handy |
1031 | is when you use the L<Coro::AIO|Coro::AIO> functions to save results to |
1032 | is when you use the L<Coro::AIO|Coro::AIO> functions to save results to |
… | |
… | |
1122 | It is very common for a coro to wait for some callback to be |
1123 | It is very common for a coro to wait for some callback to be |
1123 | called. This occurs naturally when you use coro in an otherwise |
1124 | called. This occurs naturally when you use coro in an otherwise |
1124 | event-based program, or when you use event-based libraries. |
1125 | event-based program, or when you use event-based libraries. |
1125 | |
1126 | |
1126 | These typically register a callback for some event, and call that callback |
1127 | These typically register a callback for some event, and call that callback |
1127 | when the event occured. In a coro, however, you typically want to |
1128 | when the event occurred. In a coro, however, you typically want to |
1128 | just wait for the event, simplyifying things. |
1129 | just wait for the event, simplyifying things. |
1129 | |
1130 | |
1130 | For example C<< AnyEvent->child >> registers a callback to be called when |
1131 | For example C<< AnyEvent->child >> registers a callback to be called when |
1131 | a specific child has exited: |
1132 | a specific child has exited: |
1132 | |
1133 | |
… | |
… | |
1261 | processes. What makes it so bad is that on non-windows platforms, you can |
1262 | processes. What makes it so bad is that on non-windows platforms, you can |
1262 | actually take advantage of custom hardware for this purpose (as evidenced |
1263 | actually take advantage of custom hardware for this purpose (as evidenced |
1263 | by the forks module, which gives you the (i-) threads API, just much |
1264 | by the forks module, which gives you the (i-) threads API, just much |
1264 | faster). |
1265 | faster). |
1265 | |
1266 | |
1266 | Sharing data is in the i-threads model is done by transfering data |
1267 | Sharing data is in the i-threads model is done by transferring data |
1267 | structures between threads using copying semantics, which is very slow - |
1268 | structures between threads using copying semantics, which is very slow - |
1268 | shared data simply does not exist. Benchmarks using i-threads which are |
1269 | shared data simply does not exist. Benchmarks using i-threads which are |
1269 | communication-intensive show extremely bad behaviour with i-threads (in |
1270 | communication-intensive show extremely bad behaviour with i-threads (in |
1270 | fact, so bad that Coro, which cannot take direct advantage of multiple |
1271 | fact, so bad that Coro, which cannot take direct advantage of multiple |
1271 | CPUs, is often orders of magnitude faster because it shares data using |
1272 | CPUs, is often orders of magnitude faster because it shares data using |
… | |
… | |
1301 | |
1302 | |
1302 | XS API: L<Coro::MakeMaker>. |
1303 | XS API: L<Coro::MakeMaker>. |
1303 | |
1304 | |
1304 | Low level Configuration, Thread Environment, Continuations: L<Coro::State>. |
1305 | Low level Configuration, Thread Environment, Continuations: L<Coro::State>. |
1305 | |
1306 | |
1306 | =head1 AUTHOR |
1307 | =head1 AUTHOR/SUPPORT/CONTACT |
1307 | |
1308 | |
1308 | Marc Lehmann <schmorp@schmorp.de> |
1309 | Marc A. Lehmann <schmorp@schmorp.de> |
1309 | http://home.schmorp.de/ |
1310 | http://software.schmorp.de/pkg/Coro.html |
1310 | |
1311 | |
1311 | =cut |
1312 | =cut |
1312 | |
1313 | |