Update Changes.
[p5sagit/p5-mst-13.2.git] / ext / threads / threads.pm
CommitLineData
47ba8780 1
2
3package threads;
4
5use 5.7.2;
6use strict;
7use warnings;
8
9use overload
10 '==' => \&equals,
11 'fallback' => 1;
12
13
14#use threads::Shared;
15
16require Exporter;
17require DynaLoader;
18
19use Devel::Peek;
20
21
22our @ISA = qw(Exporter DynaLoader);
23
24our %EXPORT_TAGS = ( all => [qw()]);
25
26our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
27
28our @EXPORT = qw(
29
30);
31our $VERSION = '0.05';
32
33sub new {
34 my $class = shift;
35 print (Dump($_[0]));
36 return $class->create(@_);
37}
38
39
40sub equals {
41 return 1 if($_[0]->tid() == $_[1]->tid());
42 return 0;
43}
44
45$Config::threads = 1;
46
47bootstrap threads $VERSION;
48
49
50# Preloaded methods go here.
51
521;
53__END__
54
55=head1 NAME
56
57threads - Perl extension allowing use of interpreter based threads from perl
58
59=head1 SYNOPSIS
60
61
62use threads;
63
64sub start_thread {
65 print "Thread started\n";
66}
67
68
69my $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
79thread->tid();
80
81
82
83=head1 DESCRIPTION
84
85Perl 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
91This will create a new thread with the entry point function and give it LIST as parameters.
92It will return the corresponding threads object.
93
94=item $threads->join
95
96This will wait for the corresponding thread to join. When it finishes join will return the return values of the root function.
97If a thread has been detached, join will return without wait.
98
99=item $threads->detach
100
101Will throw away the return value from the thread and make non joinable
102
103=item threads->self
104
105This will return the object for the current thread.
106
107=item $threads->tid
108
109This will return the id of the thread.
110threads->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
129Artur Bergman <lt>artur at contiller.se<gt>
130
131threads is released under the same license as Perl
132
133Thanks to
134
135Richard Soderberg <lt>rs at crystalflame.net<gt>
136Helping me out tons, trying to find reasons for races and other wierd bugs!
137
138Simon Cozens <lt>simon at brecon.co.uk<gt>
139Being there to answer zillions of annoying questions
140
141Rocco Caputo <lt>troc at netrus.net<gt>
142
143Vipul Ved Prakash <lt>mail at vipul.net<gt>
144Helping with debugging.
145
146please 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
154=back
155
156=head1 SEE ALSO
157
158L<perl>, L<perlcall>, L<perlembed>, L<perlguts>
159
160=cut
161
162
163
164