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