Fix threadcounts for arrays and hashes.
[p5sagit/p5-mst-13.2.git] / ext / threads / threads.pm
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
11 #use threads::Shared;
12
13 require Exporter;
14 require DynaLoader;
15
16 use Devel::Peek;
17
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
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
56 use threads;
57
58 sub start_thread {
59     print "Thread started\n";
60 }
61
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
74 =head1 DESCRIPTION
75
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.
81
82 =over
83
84 =item new, function, LIST
85
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.
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
125 Artur Bergman E<lt>artur at contiller.seE<gt>
126
127 threads is released under the same license as Perl
128
129 Thanks to 
130
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!
133
134 Simon Cozens E<lt>simon at brecon.co.ukE<gt>
135 Being there to answer zillions of annoying questions
136
137 Rocco Caputo E<lt>troc at netrus.netE<gt>
138
139 Vipul Ved Prakash E<lt>mail at vipul.netE<gt>
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
150 =item PERL_OLD_SIGNALS are not threadsafe, will not be.
151
152 =back
153
154 =head1 SEE ALSO
155
156 L<perl>, L<perlcall>, L<perlembed>, L<perlguts>
157
158 =cut