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

Comparing Coro-Multicore/Multicore.pm (file contents):
Revision 1.2 by root, Sat Jun 27 19:32:14 2015 UTC vs.
Revision 1.3 by root, Sat Jun 27 19:59:58 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines