… | |
… | |
8 | |
8 | |
9 | # or, if you want it disabled by default (e.g. to use it from a module) |
9 | # or, if you want it disabled by default (e.g. to use it from a module) |
10 | use Coro::Multicore (); |
10 | use Coro::Multicore (); |
11 | |
11 | |
12 | =head1 DESCRIPTION |
12 | =head1 DESCRIPTION |
|
|
13 | |
|
|
14 | EXPERIMENTAL WARNING: This module is in its early stages of |
|
|
15 | development. It's fine to try out, but it didn't receive the normal amount |
|
|
16 | of testing and real-world usage that my other modules have gone through. |
13 | |
17 | |
14 | While L<Coro> threads (unlike ithreads) provide real threads similar to |
18 | While L<Coro> threads (unlike ithreads) provide real threads similar to |
15 | pthreads, python threads and so on, they do not run in parallel to each |
19 | pthreads, python threads and so on, they do not run in parallel to each |
16 | other even on machines with multiple CPUs or multiple CPU cores. |
20 | other even on machines with multiple CPUs or multiple CPU cores. |
17 | |
21 | |
… | |
… | |
123 | |
127 | |
124 | our $WATCHER = AE::io fd, 0, \&poll; |
128 | our $WATCHER = AE::io fd, 0, \&poll; |
125 | |
129 | |
126 | =head1 INTERACTION WITH OTHER SOFTWARE |
130 | =head1 INTERACTION WITH OTHER SOFTWARE |
127 | |
131 | |
128 | TODO |
132 | This module is very similar to other environments where perl interpreters |
|
|
133 | are moved between threads, such as mod_perl2, and the same caveats apply. |
|
|
134 | |
|
|
135 | I want to spell out the most important ones: |
|
|
136 | |
|
|
137 | =over 4 |
|
|
138 | |
|
|
139 | =item pthreads usage |
|
|
140 | |
|
|
141 | Any creation of pthreads make it impossible to fork portably from a |
|
|
142 | perl program, as forking from within a threaded program will leave the |
|
|
143 | program in a state similar to a signal handler. While it might work on |
|
|
144 | some platforms (as an extension), this might also result in silent data |
|
|
145 | corruption. It also seems to work most of the time, so it's hard to test |
|
|
146 | for this. |
|
|
147 | |
|
|
148 | I recommend using something like L<AnyEvent::Fork>, which can create |
|
|
149 | subprocesses safely (via L<Proc::FastSpawn>). |
|
|
150 | |
|
|
151 | Similar issues exist for signal handlers, although this module works hard |
|
|
152 | to keep safe perl signals safe. |
|
|
153 | |
|
|
154 | =item module support |
|
|
155 | |
|
|
156 | This module moves the same perl interpreter between different |
|
|
157 | threads. Some modules might get confused by that (although this can |
|
|
158 | usually be considered a bug). This is a rare case though. |
|
|
159 | |
|
|
160 | =item event loop reliance |
|
|
161 | |
|
|
162 | To be able to wake up programs waiting for results, this module relies on |
|
|
163 | an active event loop (via L<AnyEvent>). This is used to notify the perl |
|
|
164 | interpreter when the asynchronous task is done. |
|
|
165 | |
|
|
166 | Since event loops typically fail to work properly after a fork, this means |
|
|
167 | that some operations that were formerly working will now hang after fork. |
|
|
168 | |
|
|
169 | A workaround is to call C<Coro::Multicore::enable 0> after a fork to |
|
|
170 | disable the module. |
|
|
171 | |
|
|
172 | Future versions of this module might do this automatically. |
|
|
173 | |
|
|
174 | =back |
129 | |
175 | |
130 | =head1 BUGS |
176 | =head1 BUGS |
131 | |
177 | |
132 | =over 4 |
178 | =over 4 |
133 | |
179 | |
… | |
… | |
138 | the maximum number of concurrent asynchronous tasks, this will also limit |
184 | the maximum number of concurrent asynchronous tasks, this will also limit |
139 | the maximum number of threads created. |
185 | the maximum number of threads created. |
140 | |
186 | |
141 | Future versions will likely lift this limitation. |
187 | Future versions will likely lift this limitation. |
142 | |
188 | |
143 | =item AnyEvent is initalised on module load |
189 | =item AnyEvent is initalised at module load time |
144 | |
190 | |
145 | AnyEvent is initialised on module load, as opposed to at a later time. |
191 | AnyEvent is initialised on module load, as opposed to at a later time. |
146 | |
192 | |
147 | Future versions will likely change this. |
193 | Future versions will likely change this. |
148 | |
194 | |