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

Comparing Coro/Coro.pm (file contents):
Revision 1.15 by root, Tue Jul 17 02:55:29 2001 UTC vs.
Revision 1.20 by root, Sat Jul 21 18:21:45 2001 UTC

23This module collection manages coroutines. Coroutines are similar to 23This module collection manages coroutines. Coroutines are similar to
24Threads but don't run in parallel. 24Threads but don't run in parallel.
25 25
26This module is still experimental, see the BUGS section below. 26This module is still experimental, see the BUGS section below.
27 27
28In this module, coroutines are defined as "callchain + lexical variables
29+ @_ + $_ + $@ + $^W), that is, a coroutine has it's own callchain, it's
30own set of lexicals and it's own set of perl's most important global
31variables.
32
28=cut 33=cut
29 34
30package Coro; 35package Coro;
31 36
32use Coro::State; 37use Coro::State;
33 38
34use base Exporter; 39use base Exporter;
35 40
36$VERSION = 0.06; 41$VERSION = 0.10;
37 42
38@EXPORT = qw(async yield schedule terminate); 43@EXPORT = qw(async yield schedule terminate current);
39@EXPORT_OK = qw($current); 44@EXPORT_OK = qw($current);
40 45
41{ 46{
42 use subs 'async';
43
44 my @async; 47 my @async;
45 48
46 # this way of handling attributes simply is NOT scalable ;() 49 # this way of handling attributes simply is NOT scalable ;()
47 sub import { 50 sub import {
48 Coro->export_to_level(1, @_); 51 Coro->export_to_level(1, @_);
52 my @attrs; 55 my @attrs;
53 for (@_) { 56 for (@_) {
54 if ($_ eq "Coro") { 57 if ($_ eq "Coro") {
55 push @async, $ref; 58 push @async, $ref;
56 } else { 59 } else {
57 push @attrs, @_; 60 push @attrs, $_;
58 } 61 }
59 } 62 }
60 return $old ? $old->($package, $name, @attrs) : @attrs; 63 return $old ? $old->($package, $ref, @attrs) : @attrs;
61 }; 64 };
62 } 65 }
63 66
64 sub INIT { 67 sub INIT {
65 async pop @async while @async; 68 &async(pop @async) while @async;
66 } 69 }
67} 70}
68 71
69=item $main 72=item $main
70 73
72 75
73=cut 76=cut
74 77
75our $main = new Coro; 78our $main = new Coro;
76 79
77=item $current 80=item $current (or as function: current)
78 81
79The current coroutine (the last coroutine switched to). The initial value is C<$main> (of course). 82The current coroutine (the last coroutine switched to). The initial value is C<$main> (of course).
80 83
81=cut 84=cut
82 85
84if ($current) { 87if ($current) {
85 $main->{specific} = $current->{specific}; 88 $main->{specific} = $current->{specific};
86} 89}
87 90
88our $current = $main; 91our $current = $main;
92
93sub current() { $current }
89 94
90=item $idle 95=item $idle
91 96
92The coroutine to switch to when no other coroutine is running. The default 97The coroutine to switch to when no other coroutine is running. The default
93implementation prints "FATAL: deadlock detected" and exits. 98implementation prints "FATAL: deadlock detected" and exits.
99 print STDERR "FATAL: deadlock detected\n"; 104 print STDERR "FATAL: deadlock detected\n";
100 exit(51); 105 exit(51);
101}; 106};
102 107
103# we really need priorities... 108# we really need priorities...
104## my @ready; #d#
105our @ready = (); # the ready queue. hehe, rather broken ;) 109my @ready; # the ready queue. hehe, rather broken ;)
106 110
107# static methods. not really. 111# static methods. not really.
108 112
109=head2 STATIC METHODS 113=head2 STATIC METHODS
110 114
221 225
222=cut 226=cut
223 227
2241; 2281;
225 229
226=head1 BUGS 230=head1 BUGS/LIMITATIONS
227 231
228 - could be faster, especially when the core would introduce special 232 - could be faster, especially when the core would introduce special
229 support for coroutines (like it does for threads). 233 support for coroutines (like it does for threads).
230 - there is still a memleak on coroutine termination that I could not 234 - there is still a memleak on coroutine termination that I could not
231 identify. Could be as small as a single SV. 235 identify. Could be as small as a single SV.
232 - this module is not well-tested. 236 - this module is not well-tested.
237 - if variables or arguments "disappear" (become undef) or become
238 corrupted please contact the author so he cen iron out the
239 remaining bugs.
240 - this module is not thread-safe. You must only ever use this module from
241 the same thread (this requirement might be loosened in the future to
242 allow per-thread schedulers, but Coro::State does not yet allow this).
233 243
234=head1 SEE ALSO 244=head1 SEE ALSO
235 245
236L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>, 246L<Coro::Channel>, L<Coro::Cont>, L<Coro::Specific>, L<Coro::Semaphore>,
237L<Coro::Signal>, L<Coro::State>, L<Coro::Event>. 247L<Coro::Signal>, L<Coro::State>, L<Coro::Event>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines