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

Comparing Coro/Coro.pm (file contents):
Revision 1.181 by root, Fri May 9 22:04:37 2008 UTC vs.
Revision 1.194 by root, Tue Jul 8 20:08:40 2008 UTC

35parallel access are rarely an issue, making coroutine programming much 35parallel access are rarely an issue, making coroutine programming much
36safer and easier than threads programming. 36safer and easier than threads programming.
37 37
38Unlike a normal perl program, however, coroutines allow you to have 38Unlike a normal perl program, however, coroutines allow you to have
39multiple running interpreters that share data, which is especially useful 39multiple running interpreters that share data, which is especially useful
40to code pseudo-parallel processes, such as multiple HTTP-GET requests 40to code pseudo-parallel processes and for event-based programming, such as
41running concurrently. 41multiple HTTP-GET requests running concurrently. See L<Coro::AnyEvent> to
42learn more.
42 43
43Coroutines are also useful because Perl has no support for threads (the so 44Coroutines are also useful because Perl has no support for threads (the so
44called "threads" that perl offers are nothing more than the (bad) process 45called "threads" that perl offers are nothing more than the (bad) process
45emulation coming from the Windows platform: On standard operating systems 46emulation coming from the Windows platform: On standard operating systems
46they serve no purpose whatsoever, except by making your programs slow and 47they serve no purpose whatsoever, except by making your programs slow and
65 66
66our $idle; # idle handler 67our $idle; # idle handler
67our $main; # main coroutine 68our $main; # main coroutine
68our $current; # current coroutine 69our $current; # current coroutine
69 70
70our $VERSION = 4.6; 71our $VERSION = 4.744;
71 72
72our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub); 73our @EXPORT = qw(async async_pool cede schedule terminate current unblock_sub);
73our %EXPORT_TAGS = ( 74our %EXPORT_TAGS = (
74 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)], 75 prio => [qw(PRIO_MAX PRIO_HIGH PRIO_NORMAL PRIO_LOW PRIO_IDLE PRIO_MIN)],
75); 76);
265 _pool_2 $cb; 266 _pool_2 $cb;
266 &schedule; 267 &schedule;
267 } 268 }
268 }; 269 };
269 270
271 if ($@) {
270 last if $@ eq "\3async_pool terminate\2\n"; 272 last if $@ eq "\3async_pool terminate\2\n";
271 warn $@ if $@; 273 warn $@;
274 }
272 } 275 }
273} 276}
274 277
275sub async_pool(&@) { 278sub async_pool(&@) {
276 # this is also inlined into the unlock_scheduler 279 # this is also inlined into the unlock_scheduler
610creating event callbacks that want to block. 613creating event callbacks that want to block.
611 614
612If your handler does not plan to block (e.g. simply sends a message to 615If your handler does not plan to block (e.g. simply sends a message to
613another coroutine, or puts some other coroutine into the ready queue), 616another coroutine, or puts some other coroutine into the ready queue),
614there is no reason to use C<unblock_sub>. 617there is no reason to use C<unblock_sub>.
618
619Note that you also need to use C<unblock_sub> for any other callbacks that
620are indirectly executed by any C-based event loop. For example, when you
621use a module that uses L<AnyEvent> (and you use L<Coro::AnyEvent>) and it
622provides callbacks that are the result of some event callback, then you
623must not block either, or use C<unblock_sub>.
615 624
616=cut 625=cut
617 626
618our @unblock_queue; 627our @unblock_queue;
619 628

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines