14 warn "Warning, threads::shared has already been loaded. ".
15 "To enable shared variables for these modules 'use threads' ".
16 "must be called before any of those modules are loaded\n"
17 if($threads::shared::threads_shared);
23 our @ISA = qw(Exporter DynaLoader);
25 our %EXPORT_TAGS = ( all => [qw()]);
27 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
32 our $VERSION = '0.05';
36 return 1 if($_[0]->tid() == $_[1]->tid());
40 $threads::threads = 1;
42 bootstrap threads $VERSION;
44 # why document 'new' then use 'create' in the tests!
47 # Preloaded methods go here.
54 threads - Perl extension allowing use of interpreter based threads from perl
61 print "Thread started\n";
64 my $thread = threads->create("start_thread","argument");
66 $thread->create(sub { print "I am a thread"},"argument");
72 $thread = threads->self();
81 Perl 5.6 introduced something called interpreter threads. Interpreter
82 threads are different from "5005threads" (the thread model of Perl
83 5.005) by creating a new perl interpreter per thread and not sharing
84 any data or state between threads.
86 Prior to perl 5.8 this has only been available to people embedding
87 perl and for emulating fork() on windows.
89 The threads API is loosely based on the old Thread.pm API. It is very
90 important to note that variables are not shared between threads, all
91 variables are per default thread local. To use shared variables one
92 must use threads::shared.
94 It is also important to note that you preferably enable threads by
95 doing C<use threads> as early as possible and that it is not possible
96 to enable threading inside an eval ""; In particular, if you are
97 intending to share variables with threads::shared, you must
98 C<use threads> before you C<use threads::shared> and threads will emit
99 a warning if you do it the other way around.
103 =item $thread = threads->create(function, LIST)
105 This will create a new thread with the entry point function and give
106 it LIST as parameters. It will return the corresponding threads
111 This will wait for the corresponding thread to join. When it finishes
112 join will return the return values of the entry point function. If a
113 thread has been detached, join will return without wait.
115 =item $thread->detach
117 Will throw away the return value from the thread and make it
122 This will return the object for the current thread.
126 This will return the id of the thread. threads->self->tid() is a
127 quick way to get current thread id.
135 =item Cleanup skipped %d active threads
137 The main thread exited while there were still other threads running.
138 This is not a good sign: you should either explicitly join the
139 threads, or let the threads detach themselves, or somehow be certain
140 that all the non-main threads have finished.
148 =item Fix so the return value is returned when you join.
152 =item Fix memory leaks!
156 =head1 AUTHOR and COPYRIGHT
158 Arthur Bergman E<lt>arthur at contiller.seE<gt>
160 threads is released under the same license as Perl.
164 Richard Soderberg E<lt>rs at crystalflame.netE<gt>
165 Helping me out tons, trying to find reasons for races and other weird bugs!
167 Simon Cozens E<lt>simon at brecon.co.ukE<gt>
168 Being there to answer zillions of annoying questions
170 Rocco Caputo E<lt>troc at netrus.netE<gt>
172 Vipul Ved Prakash E<lt>mail at vipul.netE<gt>
173 Helping with debugging.
175 please join perl-ithreads@perl.org for more information
181 =item creating a thread from within a thread is unsafe under win32
183 =item PERL_OLD_SIGNALS are not threadsafe, will not be.
190 L<perl>, L<threads::shared>, L<perlcall>, L<perlembed>, L<perlguts>