Commit | Line | Data |
47ba8780 |
1 | package threads; |
2 | |
3 | use 5.7.2; |
4 | use strict; |
5 | use warnings; |
6 | |
7 | use overload |
8 | '==' => \&equals, |
9 | 'fallback' => 1; |
10 | |
47ba8780 |
11 | #use threads::Shared; |
12 | |
13 | require Exporter; |
14 | require DynaLoader; |
15 | |
47ba8780 |
16 | our @ISA = qw(Exporter DynaLoader); |
17 | |
18 | our %EXPORT_TAGS = ( all => [qw()]); |
19 | |
20 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
21 | |
22 | our @EXPORT = qw( |
23 | |
24 | ); |
25 | our $VERSION = '0.05'; |
26 | |
47ba8780 |
27 | |
28 | sub equals { |
29 | return 1 if($_[0]->tid() == $_[1]->tid()); |
30 | return 0; |
31 | } |
32 | |
8222d950 |
33 | $threads::threads = 1; |
47ba8780 |
34 | |
35 | bootstrap threads $VERSION; |
36 | |
47ba8780 |
37 | # Preloaded methods go here. |
38 | |
39 | 1; |
40 | __END__ |
41 | |
42 | =head1 NAME |
43 | |
44 | threads - Perl extension allowing use of interpreter based threads from perl |
45 | |
46 | =head1 SYNOPSIS |
47 | |
47ba8780 |
48 | use threads; |
49 | |
50 | sub start_thread { |
51 | print "Thread started\n"; |
52 | } |
53 | |
47ba8780 |
54 | my $thread = threads->new("start_thread","argument"); |
55 | |
56 | $thread->new(sub { print "I am a thread"},"argument"); |
57 | |
58 | $thread->join(); |
59 | |
60 | $thread->detach(); |
61 | |
62 | $thread = threads->self(); |
63 | |
64 | thread->tid(); |
65 | |
47ba8780 |
66 | =head1 DESCRIPTION |
67 | |
ad91d581 |
68 | Perl 5.6 has something called interpreter threads, interpreter threads |
69 | are built on MULTIPLICITY and allows for several different perl |
70 | interpreters to run in different threads. This has been used in win32 |
71 | perl to fake forks, it has also been available to people embedding |
72 | perl. |
47ba8780 |
73 | |
74 | =over |
75 | |
76 | =item new, function, LIST |
77 | |
ad91d581 |
78 | This will create a new thread with the entry point function and give |
79 | it LIST as parameters. It will return the corresponding threads |
80 | object. |
47ba8780 |
81 | |
82 | =item $threads->join |
83 | |
84 | This will wait for the corresponding thread to join. When it finishes join will return the return values of the root function. |
85 | If a thread has been detached, join will return without wait. |
86 | |
87 | =item $threads->detach |
88 | |
89 | Will throw away the return value from the thread and make non joinable |
90 | |
91 | =item threads->self |
92 | |
93 | This will return the object for the current thread. |
94 | |
95 | =item $threads->tid |
96 | |
97 | This will return the id of the thread. |
98 | threads->self->tid() is a quick way to get current thread id |
99 | |
100 | =back |
101 | |
102 | |
103 | =head1 TODO |
104 | |
105 | =over |
106 | |
107 | =item Fix so the return value is returned when you join |
108 | |
109 | =item Add join_all |
110 | |
111 | =item Fix memory leaks! |
112 | |
113 | =back |
114 | |
115 | =head1 AUTHOR and COPYRIGHT |
116 | |
ad91d581 |
117 | Artur Bergman E<lt>artur at contiller.seE<gt> |
47ba8780 |
118 | |
119 | threads is released under the same license as Perl |
120 | |
121 | Thanks to |
122 | |
ad91d581 |
123 | Richard Soderberg E<lt>rs at crystalflame.netE<gt> |
124 | Helping me out tons, trying to find reasons for races and other weird bugs! |
47ba8780 |
125 | |
ad91d581 |
126 | Simon Cozens E<lt>simon at brecon.co.ukE<gt> |
127 | Being there to answer zillions of annoying questions |
47ba8780 |
128 | |
ad91d581 |
129 | Rocco Caputo E<lt>troc at netrus.netE<gt> |
47ba8780 |
130 | |
ad91d581 |
131 | Vipul Ved Prakash E<lt>mail at vipul.netE<gt> |
47ba8780 |
132 | Helping with debugging. |
133 | |
134 | please join perl-ithreads@perl.org for more information |
135 | |
136 | =head1 BUGS |
137 | |
138 | =over |
139 | |
140 | =item creating a thread from within a thread is unsafe under win32 |
141 | |
b5807cdb |
142 | =item PERL_OLD_SIGNALS are not threadsafe, will not be. |
143 | |
47ba8780 |
144 | =back |
145 | |
146 | =head1 SEE ALSO |
147 | |
148 | L<perl>, L<perlcall>, L<perlembed>, L<perlguts> |
149 | |
150 | =cut |