9 unless ($Config{useithreads}) {
10 my @caller = caller(2);
12 $caller[1] line $caller[2]:
14 This Perl hasn't been configured and built properly for the threads
15 module to work. (The 'useithreads' configuration option hasn't been used.)
17 Having threads support requires all of Perl and all of the modules in
18 the Perl installation to be rebuilt, it is not just a question of adding
19 the threads module. (In other words, threaded and non-threaded Perls
20 are binary incompatible.)
22 If you want to the use the threads module, please contact the people
25 Cannot continue, aborting.
37 warn "Warning, threads::shared has already been loaded. ".
38 "To enable shared variables for these modules 'use threads' ".
39 "must be called before any of those modules are loaded\n"
40 if($threads::shared::threads_shared);
46 our @ISA = qw(Exporter DynaLoader);
48 our %EXPORT_TAGS = ( all => [qw()]);
50 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
55 our $VERSION = '0.99';
59 return 1 if($_[0]->tid() == $_[1]->tid());
65 return threads->new($cref,@_);
68 $threads::threads = 1;
70 bootstrap threads $VERSION;
72 # why document 'new' then use 'create' in the tests!
75 # Preloaded methods go here.
82 threads - Perl extension allowing use of interpreter based threads from perl
89 print "Thread started\n";
92 my $thread = threads->create("start_thread","argument");
94 $thread->create(sub { print "I am a thread"},"argument");
100 $thread = threads->self();
103 threads->self->tid();
113 Perl 5.6 introduced something called interpreter threads. Interpreter
114 threads are different from "5005threads" (the thread model of Perl
115 5.005) by creating a new perl interpreter per thread and not sharing
116 any data or state between threads.
118 Prior to perl 5.8 this has only been available to people embedding
119 perl and for emulating fork() on windows.
121 The threads API is loosely based on the old Thread.pm API. It is very
122 important to note that variables are not shared between threads, all
123 variables are per default thread local. To use shared variables one
124 must use threads::shared.
126 It is also important to note that you preferably enable threads by
127 doing C<use threads> as early as possible and that it is not possible
128 to enable threading inside an eval ""; In particular, if you are
129 intending to share variables with threads::shared, you must
130 C<use threads> before you C<use threads::shared> and threads will emit
131 a warning if you do it the other way around.
135 =item $thread = threads->create(function, LIST)
137 This will create a new thread with the entry point function and give
138 it LIST as parameters. It will return the corresponding threads
143 This will wait for the corresponding thread to join. When it finishes
144 join will return the return values of the entry point function. If a
145 thread has been detached, an error will be thrown..
147 =item $thread->detach
149 Will throw away the return value from the thread and make it
154 This will return the object for the current thread.
158 This will return the id of the thread. threads->tid() is a quick way
159 to get current thread id if you don't have your thread handy.
161 =item threads->yield();
163 This will tell the OS to let this thread yield CPU time to other threads.
164 However this is highly depending on the underlying thread implmentation.
166 =item threads->list();
168 This will return a list of all non joined, non detached threads.
176 =item Cleanup skipped %d active threads
178 The main thread exited while there were still other threads running.
179 This is not a good sign: you should either explicitly join the threads,
180 or somehow be certain that all the non-main threads have finished.
186 The current implmentation of threads has been an attempt to get
187 a correct threading system working that could be built on,
188 and optimized, in newer versions of perl.
190 Current the overhead of creating a thread is rather large,
191 also the cost of returning values can be large. These are areas
192 were there most likely will be work done to optimize what data
193 that needs to be cloned.
197 =item Parent-Child threads.
199 On some platforms it might not be possible to destroy "parent"
200 threads while there are still existing child "threads".
202 This will be possibly be fixed in later versions of perl.
206 The tid is a 32 bit integer, it can potentially overflow.
207 This might be fixed in a later version of perl.
209 =item Returning objects
211 When you return an object the entire stash that the object is blessed
212 as well. This will lead to a large memory usage.
213 The ideal situation would be to detect the original stash if it existed.
215 =item PERL_OLD_SIGNALS are not threadsafe, will not be.
219 =head1 AUTHOR and COPYRIGHT
221 Arthur Bergman E<lt>arthur at contiller.seE<gt>
223 threads is released under the same license as Perl.
227 Richard Soderberg E<lt>rs at crystalflame.netE<gt>
228 Helping me out tons, trying to find reasons for races and other weird bugs!
230 Simon Cozens E<lt>simon at brecon.co.ukE<gt>
231 Being there to answer zillions of annoying questions
233 Rocco Caputo E<lt>troc at netrus.netE<gt>
235 Vipul Ved Prakash E<lt>mail at vipul.netE<gt>
236 Helping with debugging.
238 please join perl-ithreads@perl.org for more information
245 L<perl>, L<threads::shared>, L<perlcall>, L<perlembed>, L<perlguts>