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;
21 if (! eval 'use threads::shared; 1') {
22 print("1..0 # SKIP threads::shared not available\n");
27 print("1..5\n"); ### Number of tests that will be run ###
30 my ($TEST, $COUNT, $TOTAL);
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]);
54 print(STDERR "# FAIL: $name\n") if (! exists($ENV{'PERL_CORE'}));
61 ### Start of Testing ###
63 $SIG{'__WARN__'} = sub { ok(0, "Warning: $_[0]"); };
65 sub foo { lock($COUNT); $COUNT++; }
70 $SIG{'__WARN__'} = sub { ok(0, "BEGIN: $_[0]"); };
73 threads->create('foo')->join();
75 threads->create(\&foo)->join();
77 threads->create(sub { lock($COUNT); $COUNT++; })->join();
80 threads->create('foo')->detach();
82 threads->create(\&foo)->detach();
84 threads->create(sub { lock($COUNT); $COUNT++; })->detach();
86 $bthr = threads->create('baz');
92 threads->create('foo')->join();
94 threads->create(\&foo)->join();
96 threads->create(sub { lock($COUNT); $COUNT++; })->join();
99 threads->create('foo')->detach();
101 threads->create(\&foo)->detach();
103 threads->create(sub { lock($COUNT); $COUNT++; })->detach();
105 $mthr = threads->create('baz');
108 ok($mthr, 'Main thread');
109 ok($bthr, 'BEGIN thread');
111 ok($mthr->join() == 42, 'Main join');
112 ok($bthr->join() == 42, 'BEGIN join');
114 # Wait for detached threads to finish
119 redo if ($COUNT < $TOTAL);