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