threads - miscellaneous
[p5sagit/p5-mst-13.2.git] / ext / threads / t / end.t
CommitLineData
0f1612a7 1use strict;
2use warnings;
4e00007d 3
c3939953 4# test that END blocks are run in the thread that created them and
5# not in any child threads
6
4e00007d 7BEGIN {
0f1612a7 8 if ($ENV{'PERL_CORE'}){
9 chdir 't';
10 unshift @INC, '../lib';
11 }
12 use Config;
4e00007d 13 unless ($Config{'useithreads'}) {
14 print "1..0 # Skip: no useithreads\n";
15 exit 0;
16 }
17}
18
19use ExtUtils::testlib;
0f1612a7 20
4e00007d 21BEGIN { print "1..6\n" };
22use threads;
23use threads::shared;
24
25my $test_id = 1;
26share($test_id);
4e00007d 27
28sub ok {
29 my ($ok, $name) = @_;
30
f2cba68d 31 lock($test_id);
32
4e00007d 33 # You have to do it this way or VMS will get confused.
34 print $ok ? "ok $test_id - $name\n" : "not ok $test_id - $name\n";
35
36 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
37 $test_id++;
38 return $ok;
39}
0f1612a7 40ok(1,'Loaded');
4e00007d 41END { ok(1,"End block run once") }
42threads->create(sub { eval "END { ok(1,'') }"})->join();
43threads->create(sub { eval "END { ok(1,'') }"})->join();
44threads->create(\&thread)->join();
45
46sub thread {
47 eval "END { ok(1,'') }";
48 threads->create(sub { eval "END { ok(1,'') }"})->join();
49}