5 if ($ENV{'PERL_CORE'}){
7 unshift @INC, '../lib';
10 if (! $Config{'useithreads'}) {
11 print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
16 use ExtUtils::testlib;
22 require threads::shared;
23 import threads::shared;
25 if ($@ || ! $threads::shared::threads_shared) {
26 print("1..0 # Skip: threads::shared not available\n");
31 print("1..29\n"); ### Number of tests that will be run ###
48 # You have to do it this way or VMS will get confused.
50 print("ok $id - $name\n");
52 print("not ok $id - $name\n");
53 printf("# Failed test at line %d\n", (caller)[2]);
60 ### Start of Testing ###
62 # Tests freeing the Perl interperter for each thread
63 # See http://www.nntp.perl.org/group/perl.perl5.porters/110772 for details
65 my ($COUNT, $STARTED) :shared;
68 my $tid = threads->tid();
69 ok($tid, "Thread $tid started");
79 threads->create('threading_1')->detach();
97 ok($tid, "Thread $tid done");
103 threads->create('threading_1')->detach();
109 cond_wait($COUNT) if ($COUNT < 5);
112 threads->create(sub {
113 threads->create(sub { })->join();
119 ok($COUNT == 5, "Done - $COUNT threads");
123 my $tid = threads->tid();
124 ok($tid, "Thread $tid started");
131 threads->create('threading_2')->detach();
139 ok($tid, "Thread $tid done");
145 threads->create('threading_2')->detach();
146 threads->create(sub {
147 threads->create(sub { })->join();
157 ok($COUNT == 5, "Done - $COUNT threads");
161 threads->create(sub { })->join();
167 my $tid = threads->tid();
168 ok($tid, "Thread $tid started");
171 threads->create(sub {
172 my $tid = threads->tid();
173 ok($tid, "Thread $tid started");
181 ok($tid, "Thread $tid done");
189 ok($tid, "Thread $tid done");
194 threads->create(sub {
195 threads->create('threading_3')->detach();
205 ok($COUNT == 2, "Done - $COUNT threads");