ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro-Multicore/Multicore.pm
Revision: 1.3
Committed: Sat Jun 27 19:59:58 2015 UTC (8 years, 11 months ago) by root
Branch: MAIN
Changes since 1.2: +38 -8 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Coro::Multicore - make coro threads on multiple cores with specially supported modules
4
5 =head1 SYNOPSIS
6
7 use Coro::Multicore;
8
9 =head1 DESCRIPTION
10
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 each
13 other even on machines with multiple CPUs or multiple CPU cores.
14
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
17 touch any perl data structures, and secondly, the XS code is specially
18 prepared to allow this.
19
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.
22
23 The mechanism to support this is easily added to existing modules
24 and is independent of L<Coro> or L<Coro::Multicore>, and therefore
25 could be used, without changes, with other, similar, modules, or even
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>
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:
47
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
62
63 =cut
64
65 package Coro::Multicore;
66
67 use Coro ();
68 use AnyEvent ();
69
70 BEGIN {
71 our $VERSION = 0.02;
72
73 use XSLoader;
74 XSLoader::load __PACKAGE__, $VERSION;
75 }
76
77 our $WATCHER = AE::io fd, 0, \&poll;
78
79 =head1 AUTHOR
80
81 Marc Lehmann <schmorp@schmorp.de>
82 http://software.schmorp.de/pkg/AnyEvent-XSThreadPool.html
83
84 =cut
85
86 1
87