Upgrade to threads 1.75
[p5sagit/p5-mst-13.2.git] / dist / threads / t / end.t
CommitLineData
0f1612a7 1use strict;
2use warnings;
4e00007d 3
4BEGIN {
0f1612a7 5 use Config;
fc04eb16 6 if (! $Config{'useithreads'}) {
561ee912 7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n");
fc04eb16 8 exit(0);
4e00007d 9 }
10}
11
12use ExtUtils::testlib;
0f1612a7 13
4e00007d 14use threads;
4e00007d 15
fc04eb16 16BEGIN {
e301958b 17 if (! eval 'use threads::shared; 1') {
561ee912 18 print("1..0 # SKIP threads::shared not available\n");
58a3a76c 19 exit(0);
20 }
21
fc04eb16 22 $| = 1;
23 print("1..6\n"); ### Number of tests that will be run ###
24};
25
4dcb9e53 26my $TEST;
27BEGIN {
28 share($TEST);
29 $TEST = 1;
30}
fc04eb16 31
32ok(1, 'Loaded');
4e00007d 33
34sub ok {
35 my ($ok, $name) = @_;
36
fc04eb16 37 lock($TEST);
38 my $id = $TEST++;
f2cba68d 39
4e00007d 40 # You have to do it this way or VMS will get confused.
fc04eb16 41 if ($ok) {
42 print("ok $id - $name\n");
43 } else {
44 print("not ok $id - $name\n");
45 printf("# Failed test at line %d\n", (caller)[2]);
46 }
4e00007d 47
fc04eb16 48 return ($ok);
4e00007d 49}
fc04eb16 50
51
52### Start of Testing ###
53
54# Test that END blocks are run in the thread that created them,
55# and not in any child threads.
56
57END {
58 ok(1, 'Main END block')
59}
60
61threads->create(sub { eval "END { ok(1, '1st thread END block') }"})->join();
62threads->create(sub { eval "END { ok(1, '2nd thread END block') }"})->join();
4e00007d 63
64sub thread {
fc04eb16 65 eval "END { ok(1, '4th thread END block') }";
66 threads->create(sub { eval "END { ok(1, '5th thread END block') }"})->join();
4e00007d 67}
fc04eb16 68threads->create(\&thread)->join();
69
561ee912 70exit(0);
71
fc04eb16 72# EOF