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..5\n"); ### Number of tests that will be run ###
45 # You have to do it this way or VMS will get confused.
47 print("ok $id - $name\n");
49 print("not ok $id - $name\n");
50 printf("# Failed test at line %d\n", (caller)[2]);
57 ### Start of Testing ###
59 $SIG{'__WARN__'} = sub { ok(0, "Warning: $_[0]"); };
66 $SIG{'__WARN__'} = sub { ok(0, "BEGIN: $_[0]"); };
68 threads->create('foo')->join();
69 threads->create(\&foo)->join();
70 threads->create(sub {})->join();
72 threads->create('foo')->detach();
73 threads->create(\&foo)->detach();
74 threads->create(sub {})->detach();
76 $bthr = threads->create('baz');
81 threads->create('foo')->join();
82 threads->create(\&foo)->join();
83 threads->create(sub {})->join();
85 threads->create('foo')->detach();
86 threads->create(\&foo)->detach();
87 threads->create(sub {})->detach();
89 $mthr = threads->create('baz');
92 ok($mthr, 'Main thread');
93 ok($bthr, 'BEGIN thread');
95 ok($mthr->join() == 42, 'Main join');
96 ok($bthr->join() == 42, 'BEGIN join');
98 # make sure a still-running detached thread doesn't give a warning on exit
100 # *** add new tests above this one
101 threads->create(sub { 1 while 1 })->detach();
102 # *** add new tests above this one