… | |
… | |
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.51; |
371 | our $VERSION = 6.512; |
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 | ); |
… | |
… | |
638 | # at this place, the timezone is Antarctica/South_Pole, |
638 | # at this place, the timezone is Antarctica/South_Pole, |
639 | # without disturbing the TZ of any other coro. |
639 | # without disturbing the TZ of any other coro. |
640 | }; |
640 | }; |
641 | |
641 | |
642 | 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 |
643 | working directory etc.) to a block, despite the existance of other |
643 | working directory etc.) to a block, despite the existence of other |
644 | coros. |
644 | coros. |
645 | |
645 | |
646 | Another interesting example implements time-sliced multitasking using |
646 | Another interesting example implements time-sliced multitasking using |
647 | interval timers (this could obviously be optimised, but does the job): |
647 | interval timers (this could obviously be optimised, but does the job): |
648 | |
648 | |
… | |
… | |
754 | =item $state->is_new |
754 | =item $state->is_new |
755 | |
755 | |
756 | 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 |
757 | 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 |
758 | the arguments, but consumes very little other resources. New states will |
758 | the arguments, but consumes very little other resources. New states will |
759 | automatically get assigned a perl interpreter when they are transfered to. |
759 | automatically get assigned a perl interpreter when they are transferred to. |
760 | |
760 | |
761 | =item $state->is_zombie |
761 | =item $state->is_zombie |
762 | |
762 | |
763 | Returns true iff the Coro object has been cancelled, i.e. |
763 | Returns true iff the Coro object has been cancelled, i.e. |
764 | 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, |
… | |
… | |
1123 | 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 |
1124 | called. This occurs naturally when you use coro in an otherwise |
1124 | called. This occurs naturally when you use coro in an otherwise |
1125 | event-based program, or when you use event-based libraries. |
1125 | event-based program, or when you use event-based libraries. |
1126 | |
1126 | |
1127 | 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 |
1128 | 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 |
1129 | just wait for the event, simplyifying things. |
1129 | just wait for the event, simplyifying things. |
1130 | |
1130 | |
1131 | 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 |
1132 | a specific child has exited: |
1132 | a specific child has exited: |
1133 | |
1133 | |
… | |
… | |
1262 | 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 |
1263 | actually take advantage of custom hardware for this purpose (as evidenced |
1263 | actually take advantage of custom hardware for this purpose (as evidenced |
1264 | 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 |
1265 | faster). |
1265 | faster). |
1266 | |
1266 | |
1267 | 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 |
1268 | structures between threads using copying semantics, which is very slow - |
1268 | structures between threads using copying semantics, which is very slow - |
1269 | 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 |
1270 | communication-intensive show extremely bad behaviour with i-threads (in |
1270 | communication-intensive show extremely bad behaviour with i-threads (in |
1271 | 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 |
1272 | 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 |