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

Comparing Coro/Coro/State.pm (file contents):
Revision 1.8 by root, Sat Jul 21 18:21:45 2001 UTC vs.
Revision 1.9 by root, Mon Jul 23 22:09:39 2001 UTC

29greatly reduced. 29greatly reduced.
30 30
31This module provides only low-level functionality. See L<Coro> and related 31This module provides only low-level functionality. See L<Coro> and related
32modules for a more useful process abstraction including scheduling. 32modules for a more useful process abstraction including scheduling.
33 33
34=head2 MEMORY CONSUMPTION
35
36A newly created coroutine that has not been used only allocates a
37relatively small (a few hundred bytes) structure. Only on the first
38C<transfer> will perl stacks (a few k) and optionally C stack (4-16k) be
39allocated. On systems supporting mmap a 128k stack is allocated, on the
40assumption that the OS has on-demand virtual memory. All this is very
41system-dependent. On my i686-pc-linux-gnu system this amounts to about 10k
42per coroutine.
43
34=over 4 44=over 4
35 45
36=cut 46=cut
37 47
38package Coro::State; 48package Coro::State;
44 XSLoader::load Coro::State, $VERSION; 54 XSLoader::load Coro::State, $VERSION;
45} 55}
46 56
47use base 'Exporter'; 57use base 'Exporter';
48 58
49@EXPORT_OK = qw(SAVE_DEFAV SAVE_DEFSV SAVE_ERRSV); 59@EXPORT_OK = qw(SAVE_DEFAV SAVE_DEFSV SAVE_ERRSV SAVE_CCTXT);
50 60
51=item $coro = new [$coderef] [, @args...] 61=item $coro = new [$coderef] [, @args...]
52 62
53Create a new coroutine and return it. The first C<transfer> call to this 63Create a new coroutine and return it. The first C<transfer> call to this
54coroutine will start execution at the given coderef. If, the subroutine 64coroutine will start execution at the given coderef. If, the subroutine
55returns it will be executed again. 65returns it will be executed again.
56
57The coderef you submit MUST NOT be a closure that refers to variables
58in an outer scope. This does NOT work.
59 66
60If the coderef is omitted this function will create a new "empty" 67If the coderef is omitted this function will create a new "empty"
61coroutine, i.e. a coroutine that cannot be transfered to but can be used 68coroutine, i.e. a coroutine that cannot be transfered to but can be used
62to save the current coroutine in. 69to save the current coroutine in.
63 70
90The "state" of a subroutine includes the scope, i.e. lexical variables and 97The "state" of a subroutine includes the scope, i.e. lexical variables and
91the current execution state. The C<$flags> value can be used to specify 98the current execution state. The C<$flags> value can be used to specify
92that additional state be saved (and later restored), by C<||>-ing the 99that additional state be saved (and later restored), by C<||>-ing the
93following constants together: 100following constants together:
94 101
95 Constant Effect 102 Constant Effect
96 SAVE_DEFAV save/restore @_ 103 SAVE_DEFAV save/restore @_
97 SAVE_DEFSV save/restore $_ 104 SAVE_DEFSV save/restore $_
98 SAVE_ERRSV save/restore $@ 105 SAVE_ERRSV save/restore $@
106 SAVE_CCTXT save/restore C-stack (you usually want this)
99 107
100These constants are not exported by default. The default is subject to 108These constants are not exported by default. The default is subject to
101change (because we are still at an early development stage) but will 109change (because we are still at an early development stage) but will
102stabilize. 110stabilize.
103 111
105remember that every function call that might call C<transfer> (such 113remember that every function call that might call C<transfer> (such
106as C<Coro::Channel::put>) might clobber any global and/or special 114as C<Coro::Channel::put>) might clobber any global and/or special
107variables. Yes, this is by design ;) You can always create your own 115variables. Yes, this is by design ;) You can always create your own
108process abstraction model that saves these variables. 116process abstraction model that saves these variables.
109 117
110The easiest way to do this is to create your own scheduling primitive like this: 118The easiest way to do this is to create your own scheduling primitive like
119this:
111 120
112 sub schedule { 121 sub schedule {
113 local ($_, $@, ...); 122 local ($_, $@, ...);
114 $old->transfer($new); 123 $old->transfer($new);
115 } 124 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines