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