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