6 if (! $Config{'useithreads'}) {
7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
12 use ExtUtils::testlib;
17 if (! eval 'use threads::shared; 1') {
18 print("1..0 # SKIP threads::shared not available\n");
23 print("1..5\n"); ### Number of tests that will be run ###
26 my ($TEST, $COUNT, $TOTAL);
44 # You have to do it this way or VMS will get confused.
46 print("ok $id - $name\n");
48 print("not ok $id - $name\n");
49 printf("# Failed test at line %d\n", (caller)[2]);
50 print(STDERR "# FAIL: $name\n") if (! $ENV{'PERL_CORE'});
57 ### Start of Testing ###
59 $SIG{'__WARN__'} = sub { ok(0, "Warning: $_[0]"); };
61 sub foo { lock($COUNT); $COUNT++; }
66 $SIG{'__WARN__'} = sub { ok(0, "BEGIN: $_[0]"); };
69 threads->create('foo')->join();
71 threads->create(\&foo)->join();
73 threads->create(sub { lock($COUNT); $COUNT++; })->join();
76 threads->create('foo')->detach();
78 threads->create(\&foo)->detach();
80 threads->create(sub { lock($COUNT); $COUNT++; })->detach();
82 $bthr = threads->create('baz');
88 threads->create('foo')->join();
90 threads->create(\&foo)->join();
92 threads->create(sub { lock($COUNT); $COUNT++; })->join();
95 threads->create('foo')->detach();
97 threads->create(\&foo)->detach();
99 threads->create(sub { lock($COUNT); $COUNT++; })->detach();
101 $mthr = threads->create('baz');
104 ok($mthr, 'Main thread');
105 ok($bthr, 'BEGIN thread');
107 ok($mthr->join() == 42, 'Main join');
108 ok($bthr->join() == 42, 'BEGIN join');
110 # Wait for detached threads to finish
115 redo if ($COUNT < $TOTAL);