ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/README
Revision: 1.3
Committed: Mon Nov 6 19:56:26 2006 UTC (17 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-2_5, stack_sharing
Changes since 1.2: +4 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 NAME
2     Coro - coroutine process abstraction
3    
4     SYNOPSIS
5     use Coro;
6    
7     async {
8     # some asynchronous thread of execution
9     };
10    
11     # alternatively create an async process like this:
12    
13     sub some_func : Coro {
14     # some more async code
15     }
16    
17     cede;
18    
19     DESCRIPTION
20     This module collection manages coroutines. Coroutines are similar to
21     threads but don't run in parallel.
22    
23     In this module, coroutines are defined as "callchain + lexical variables
24     + @_ + $_ + $@ + $^W + C stack), that is, a coroutine has it's own
25     callchain, it's own set of lexicals and it's own set of perl's most
26     important global variables.
27    
28     $main
29     This coroutine represents the main program.
30    
31     $current (or as function: current)
32     The current coroutine (the last coroutine switched to). The initial
33     value is $main (of course).
34    
35     $idle
36     The coroutine to switch to when no other coroutine is running. The
37     default implementation prints "FATAL: deadlock detected" and exits.
38    
39     STATIC METHODS
40     Static methods are actually functions that operate on the current
41     process only.
42    
43     async { ... } [@args...]
44     Create a new asynchronous process and return it's process object
45     (usually unused). When the sub returns the new process is
46     automatically terminated.
47    
48 root 1.3 When the coroutine dies, the program will exit, just as in the main
49     program.
50    
51 root 1.1 # create a new coroutine that just prints its arguments
52     async {
53     print "@_\n";
54     } 1,2,3,4;
55    
56     schedule
57     Calls the scheduler. Please note that the current process will not
58     be put into the ready queue, so calling this function usually means
59     you will never be called again.
60    
61     cede
62     "Cede" to other processes. This function puts the current process
63     into the ready queue and calls "schedule", which has the effect of
64     giving up the current "timeslice" to other coroutines of the same or
65     higher priority.
66    
67     terminate [arg...]
68     Terminates the current process with the given status values (see
69     cancel).
70    
71     # dynamic methods
72    
73     PROCESS METHODS
74     These are the methods you can call on process objects.
75    
76     new Coro \&sub [, @args...]
77     Create a new process and return it. When the sub returns the process
78     automatically terminates as if "terminate" with the returned values
79     were called. To make the process run you must first put it into the
80     ready queue by calling the ready method.
81    
82     $process->ready
83     Put the given process into the ready queue.
84    
85     $process->cancel (arg...)
86 root 1.3 Terminates the given process and makes it return the given arguments
87 root 1.1 as status (default: the empty list).
88    
89     $process->join
90     Wait until the coroutine terminates and return any values given to
91     the "terminate" or "cancel" functions. "join" can be called multiple
92     times from multiple processes.
93    
94     $oldprio = $process->prio($newprio)
95     Sets (or gets, if the argument is missing) the priority of the
96     process. Higher priority processes get run before lower priority
97     processes. Priorities are small signed integers (currently -4 ..
98     +3), that you can refer to using PRIO_xxx constants (use the import
99     tag :prio to get then):
100    
101     PRIO_MAX > PRIO_HIGH > PRIO_NORMAL > PRIO_LOW > PRIO_IDLE > PRIO_MIN
102     3 > 1 > 0 > -1 > -3 > -4
103    
104     # set priority to HIGH
105     current->prio(PRIO_HIGH);
106    
107     The idle coroutine ($Coro::idle) always has a lower priority than
108     any existing coroutine.
109    
110     Changing the priority of the current process will take effect
111     immediately, but changing the priority of processes in the ready
112     queue (but not running) will only take effect after the next
113     schedule (of that process). This is a bug that will be fixed in some
114     future version.
115    
116     $newprio = $process->nice($change)
117     Similar to "prio", but subtract the given value from the priority
118     (i.e. higher values mean lower priority, just as in unix).
119    
120     $olddesc = $process->desc($newdesc)
121     Sets (or gets in case the argument is missing) the description for
122     this process. This is just a free-form string you can associate with
123     a process.
124    
125     BUGS/LIMITATIONS
126     - you must make very sure that no coro is still active on global
127     destruction. very bad things might happen otherwise (usually segfaults).
128    
129     - this module is not thread-safe. You should only ever use this module
130     from the same thread (this requirement might be losened in the future
131     to allow per-thread schedulers, but Coro::State does not yet allow
132     this).
133    
134     SEE ALSO
135 root 1.2 Support/Utility: Coro::Cont, Coro::Specific, Coro::State, Coro::Util.
136    
137     Locking/IPC: Coro::Signal, Coro::Channel, Coro::Semaphore,
138     Coro::SemaphoreSet, Coro::RWLock.
139    
140     Event/IO: Coro::Timer, Coro::Event, Coro::Handle, Coro::Socket,
141     Coro::Select.
142    
143     Embedding: <Coro:MakeMaker>
144 root 1.1
145     AUTHOR
146     Marc Lehmann <schmorp@schmorp.de>
147     http://home.schmorp.de/
148