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

Comparing Coro/Coro.pm (file contents):
Revision 1.6 by root, Tue Jul 10 21:19:47 2001 UTC vs.
Revision 1.7 by root, Fri Jul 13 13:05:38 2001 UTC

72 }, $class; 72 }, $class;
73} 73}
74 74
75=item $prev->transfer($next) 75=item $prev->transfer($next)
76 76
77Save the state of the current subroutine in $prev and switch to the 77Save the state of the current subroutine in C<$prev> and switch to the
78coroutine saved in $next. 78coroutine saved in C<$next>.
79
80The "state" of a subroutine only ever includes scope, i.e. lexical
81variables and the current execution state. It does not save/restore any
82global variables such as C<$_> or C<$@> or any other special or non
83special variables. So remember that every function call that might call
84C<transfer> (such as C<Coro::Channel::put>) might clobber any global
85and/or special variables. Yes, this is by design ;) You cna always create
86your own process abstraction model that saves these variables.
87
88The easiest way to do this is to create your own scheduling primitive like this:
89
90 sub schedule {
91 local ($_, $@, ...);
92 $old->transfer($new);
93 }
79 94
80=cut 95=cut
81 96
82# I call the _transfer function from a perl function 97# I call the _transfer function from a perl function
83# because that way perl saves all important things on 98# because that way perl saves all important things on
84# the stack. 99# the stack. Actually, I'd do it from within XS, but
100# I couldn't get it to work.
85sub transfer { 101sub transfer {
86 _transfer($_[0], $_[1]); 102 _transfer($_[0], $_[1]);
87} 103}
88 104
89=item $error, $error_msg, $error_coro 105=item $error, $error_msg, $error_coro

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines