… | |
… | |
7 | use Coro::Multicore; |
7 | use Coro::Multicore; |
8 | |
8 | |
9 | =head1 DESCRIPTION |
9 | =head1 DESCRIPTION |
10 | |
10 | |
11 | While L<Coro> threads (unlike ithreads) provide real threads similar to |
11 | While L<Coro> threads (unlike ithreads) provide real threads similar to |
12 | pthreads, python threads and so on, they do not run in parallel to eahc |
12 | pthreads, python threads and so on, they do not run in parallel to each |
13 | other even on machines with multiple CPUs or multiple CPU cores. |
13 | other even on machines with multiple CPUs or multiple CPU cores. |
14 | |
14 | |
15 | This module lifts this restriction under two very specific but useful |
15 | This module lifts this restriction under two very specific but useful |
16 | conditions: firstly, the coro thread executes in XS code and does not |
16 | conditions: firstly, the coro thread executes in XS code and does not |
17 | touch any perl data structures, and secondly, the XS code is specially |
17 | touch any perl data structures, and secondly, the XS code is specially |
18 | prepared to allow this. |
18 | prepared to allow this. |
19 | |
19 | |
20 | This means that, when you call an XS function of a module prepared for it, |
20 | This means that, when you call an XS function of a module prepared for it, |
21 | this XS function can execute in parallel to any other Coro threads. |
21 | this XS function can execute in parallel to any other Coro threads. |
22 | |
22 | |
23 | The mechanism to support this is easily added to existing modules and is |
23 | The mechanism to support this is easily added to existing modules |
24 | independent of L<Coro> or L<Coro::Multicore>, and therefore could be used, |
24 | and is independent of L<Coro> or L<Coro::Multicore>, and therefore |
25 | without changes, with other, similar, modules, or even the perl core, |
25 | could be used, without changes, with other, similar, modules, or even |
26 | should it gain real thread support anytime soon. SEe L<TODO> for more info |
26 | the perl core, should it gain real thread support anytime soon. See |
|
|
27 | L<http://pod.tst.eu/http://cvs.schmorp.de/Coro-Multicore/perlmulticore.h> |
27 | on how to prepare a module to allow parallel execution. |
28 | for more info on how to prepare a module to allow parallel execution. |
|
|
29 | |
|
|
30 | This module is an L<AnyEvent> user (and also, if not obvious, uses |
|
|
31 | L<Coro>). |
|
|
32 | |
|
|
33 | =head1 HOW TO USE IT |
|
|
34 | |
|
|
35 | It could hardly be simpler - if you use coro threads, and before you call |
|
|
36 | a supported lengthy operation implemented in XS, use this module and other |
|
|
37 | coro threads can run in parallel: |
|
|
38 | |
|
|
39 | use Coro::Multicore; |
|
|
40 | |
|
|
41 | This module has no important API functions to learn or remember. All you |
|
|
42 | need to do is I<load> it before you can take advantage of it. |
|
|
43 | |
|
|
44 | =head1 API FUNCTION |
|
|
45 | |
|
|
46 | There is currently a lone API function documented for this module: |
28 | |
47 | |
29 | =over 4 |
48 | =over 4 |
|
|
49 | |
|
|
50 | =item $previous = Coro::Multicore::max_idle_threads [$count] |
|
|
51 | |
|
|
52 | To run on multiple cores, this module creates I<threads>. Since thread |
|
|
53 | creation is costly, it will keep some of them around for future uses. This |
|
|
54 | function returns the current maximum number of threads that are being kept |
|
|
55 | around (default: C<8>), and can be used to set a new limit, in case you |
|
|
56 | have bigger requirements. |
|
|
57 | |
|
|
58 | Future implementations will also provide a timeout mechanism, for even |
|
|
59 | better behaviour. |
|
|
60 | |
|
|
61 | =back |
30 | |
62 | |
31 | =cut |
63 | =cut |
32 | |
64 | |
33 | package Coro::Multicore; |
65 | package Coro::Multicore; |
34 | |
66 | |
… | |
… | |
42 | XSLoader::load __PACKAGE__, $VERSION; |
74 | XSLoader::load __PACKAGE__, $VERSION; |
43 | } |
75 | } |
44 | |
76 | |
45 | our $WATCHER = AE::io fd, 0, \&poll; |
77 | our $WATCHER = AE::io fd, 0, \&poll; |
46 | |
78 | |
47 | =back |
|
|
48 | |
|
|
49 | =head1 AUTHOR |
79 | =head1 AUTHOR |
50 | |
80 | |
51 | Marc Lehmann <schmorp@schmorp.de> |
81 | Marc Lehmann <schmorp@schmorp.de> |
52 | http://software.schmorp.de/pkg/AnyEvent-XSThreadPool.html |
82 | http://software.schmorp.de/pkg/AnyEvent-XSThreadPool.html |
53 | |
83 | |