… | |
… | |
7 | |
7 | |
8 | # or, if you want it disabled by default (e.g. to use it from a module) |
8 | # or, if you want it disabled by default (e.g. to use it from a module) |
9 | use Coro::Multicore (); |
9 | use Coro::Multicore (); |
10 | |
10 | |
11 | DESCRIPTION |
11 | DESCRIPTION |
|
|
12 | EXPERIMENTAL WARNING: This module is in its early stages of development. |
|
|
13 | It's fine to try out, but it didn't receive the normal amount of testing |
|
|
14 | and real-world usage that my other modules have gone through. |
|
|
15 | |
12 | While Coro threads (unlike ithreads) provide real threads similar to |
16 | While Coro threads (unlike ithreads) provide real threads similar to |
13 | pthreads, python threads and so on, they do not run in parallel to each |
17 | pthreads, python threads and so on, they do not run in parallel to each |
14 | other even on machines with multiple CPUs or multiple CPU cores. |
18 | other even on machines with multiple CPUs or multiple CPU cores. |
15 | |
19 | |
16 | This module lifts this restriction under two very specific but useful |
20 | This module lifts this restriction under two very specific but useful |
… | |
… | |
86 | Coro::Multicore::scoped_disable |
90 | Coro::Multicore::scoped_disable |
87 | The opposite of "Coro::Multicore::scope_disable": instructs |
91 | The opposite of "Coro::Multicore::scope_disable": instructs |
88 | Coro::Multicore to *not* handle the next multicore-enabled request. |
92 | Coro::Multicore to *not* handle the next multicore-enabled request. |
89 | |
93 | |
90 | INTERACTION WITH OTHER SOFTWARE |
94 | INTERACTION WITH OTHER SOFTWARE |
91 | TODO |
95 | This module is very similar to other environments where perl |
|
|
96 | interpreters are moved between threads, such as mod_perl2, and the same |
|
|
97 | caveats apply. |
|
|
98 | |
|
|
99 | I want to spell out the most important ones: |
|
|
100 | |
|
|
101 | pthreads usage |
|
|
102 | Any creation of pthreads make it impossible to fork portably from a |
|
|
103 | perl program, as forking from within a threaded program will leave |
|
|
104 | the program in a state similar to a signal handler. While it might |
|
|
105 | work on some platforms (as an extension), this might also result in |
|
|
106 | silent data corruption. It also seems to work most of the time, so |
|
|
107 | it's hard to test for this. |
|
|
108 | |
|
|
109 | I recommend using something like AnyEvent::Fork, which can create |
|
|
110 | subprocesses safely (via Proc::FastSpawn). |
|
|
111 | |
|
|
112 | Similar issues exist for signal handlers, although this module works |
|
|
113 | hard to keep safe perl signals safe. |
|
|
114 | |
|
|
115 | module support |
|
|
116 | This module moves the same perl interpreter between different |
|
|
117 | threads. Some modules might get confused by that (although this can |
|
|
118 | usually be considered a bug). This is a rare case though. |
|
|
119 | |
|
|
120 | event loop reliance |
|
|
121 | To be able to wake up programs waiting for results, this module |
|
|
122 | relies on an active event loop (via AnyEvent). This is used to |
|
|
123 | notify the perl interpreter when the asynchronous task is done. |
|
|
124 | |
|
|
125 | Since event loops typically fail to work properly after a fork, this |
|
|
126 | means that some operations that were formerly working will now hang |
|
|
127 | after fork. |
|
|
128 | |
|
|
129 | A workaround is to call "Coro::Multicore::enable 0" after a fork to |
|
|
130 | disable the module. |
|
|
131 | |
|
|
132 | Future versions of this module might do this automatically. |
92 | |
133 | |
93 | BUGS |
134 | BUGS |
94 | (OS-) threads are never released |
135 | (OS-) threads are never released |
95 | At the moment, threads that were created once will never be freed. |
136 | At the moment, threads that were created once will never be freed. |
96 | They will be reused for asynchronous requests, though, so a slong as |
137 | They will be reused for asynchronous requests, though, so a slong as |
97 | you limit the maximum number of concurrent asynchronous tasks, this |
138 | you limit the maximum number of concurrent asynchronous tasks, this |
98 | will also limit the maximum number of threads created. |
139 | will also limit the maximum number of threads created. |
99 | |
140 | |
100 | Future versions will likely lift this limitation. |
141 | Future versions will likely lift this limitation. |
101 | |
142 | |
102 | AnyEvent is initalised on module load |
143 | AnyEvent is initalised at module load time |
103 | AnyEvent is initialised on module load, as opposed to at a later |
144 | AnyEvent is initialised on module load, as opposed to at a later |
104 | time. |
145 | time. |
105 | |
146 | |
106 | Future versions will likely change this. |
147 | Future versions will likely change this. |
107 | |
148 | |