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