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

Comparing Coro/Coro.pm (file contents):
Revision 1.343 by root, Sun Jun 26 21:46:03 2016 UTC vs.
Revision 1.344 by root, Fri Jul 14 03:02:44 2017 UTC

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
642This can be used to localise about any resource (locale, uid, current 642This can be used to localise about any resource (locale, uid, current
643working directory etc.) to a block, despite the existance of other 643working directory etc.) to a block, despite the existence of other
644coros. 644coros.
645 645
646Another interesting example implements time-sliced multitasking using 646Another interesting example implements time-sliced multitasking using
647interval timers (this could obviously be optimised, but does the job): 647interval timers (this could obviously be optimised, but does the job):
648 648
754=item $state->is_new 754=item $state->is_new
755 755
756Returns 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
757yet. 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
758the arguments, but consumes very little other resources. New states will 758the arguments, but consumes very little other resources. New states will
759automatically get assigned a perl interpreter when they are transfered to. 759automatically get assigned a perl interpreter when they are transferred to.
760 760
761=item $state->is_zombie 761=item $state->is_zombie
762 762
763Returns true iff the Coro object has been cancelled, i.e. 763Returns true iff the Coro object has been cancelled, i.e.
764it'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,
1123It 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
1124called. This occurs naturally when you use coro in an otherwise 1124called. This occurs naturally when you use coro in an otherwise
1125event-based program, or when you use event-based libraries. 1125event-based program, or when you use event-based libraries.
1126 1126
1127These typically register a callback for some event, and call that callback 1127These typically register a callback for some event, and call that callback
1128when the event occured. In a coro, however, you typically want to 1128when the event occurred. In a coro, however, you typically want to
1129just wait for the event, simplyifying things. 1129just wait for the event, simplyifying things.
1130 1130
1131For example C<< AnyEvent->child >> registers a callback to be called when 1131For example C<< AnyEvent->child >> registers a callback to be called when
1132a specific child has exited: 1132a specific child has exited:
1133 1133
1262processes. 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
1263actually take advantage of custom hardware for this purpose (as evidenced 1263actually take advantage of custom hardware for this purpose (as evidenced
1264by 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
1265faster). 1265faster).
1266 1266
1267Sharing 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
1268structures between threads using copying semantics, which is very slow - 1268structures between threads using copying semantics, which is very slow -
1269shared data simply does not exist. Benchmarks using i-threads which are 1269shared data simply does not exist. Benchmarks using i-threads which are
1270communication-intensive show extremely bad behaviour with i-threads (in 1270communication-intensive show extremely bad behaviour with i-threads (in
1271fact, so bad that Coro, which cannot take direct advantage of multiple 1271fact, so bad that Coro, which cannot take direct advantage of multiple
1272CPUs, 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