| Line | |
|---|
| 1 |
|
|---|
| 2 | # test that END blocks are run in the thread that created them and
|
|---|
| 3 | # not in any child threads
|
|---|
| 4 |
|
|---|
| 5 | BEGIN {
|
|---|
| 6 | chdir 't' if -d 't';
|
|---|
| 7 | push @INC, '../lib';
|
|---|
| 8 | require Config; import Config;
|
|---|
| 9 | unless ($Config{'useithreads'}) {
|
|---|
| 10 | print "1..0 # Skip: no useithreads\n";
|
|---|
| 11 | exit 0;
|
|---|
| 12 | }
|
|---|
| 13 | if ($Config{'extensions'} !~ /\bDevel\/Peek\b/) {
|
|---|
| 14 | print "1..0 # Skip: Devel::Peek was not built\n";
|
|---|
| 15 | exit 0;
|
|---|
| 16 | }
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | use ExtUtils::testlib;
|
|---|
| 20 | use strict;
|
|---|
| 21 | BEGIN { print "1..6\n" };
|
|---|
| 22 | use threads;
|
|---|
| 23 | use threads::shared;
|
|---|
| 24 |
|
|---|
| 25 | my $test_id = 1;
|
|---|
| 26 | share($test_id);
|
|---|
| 27 | use Devel::Peek qw(Dump);
|
|---|
| 28 |
|
|---|
| 29 | sub ok {
|
|---|
| 30 | my ($ok, $name) = @_;
|
|---|
| 31 |
|
|---|
| 32 | # You have to do it this way or VMS will get confused.
|
|---|
| 33 | print $ok ? "ok $test_id - $name\n" : "not ok $test_id - $name\n";
|
|---|
| 34 |
|
|---|
| 35 | printf "# Failed test at line %d\n", (caller)[2] unless $ok;
|
|---|
| 36 | $test_id++;
|
|---|
| 37 | return $ok;
|
|---|
| 38 | }
|
|---|
| 39 | ok(1,'');
|
|---|
| 40 | END { ok(1,"End block run once") }
|
|---|
| 41 | threads->create(sub { eval "END { ok(1,'') }"})->join();
|
|---|
| 42 | threads->create(sub { eval "END { ok(1,'') }"})->join();
|
|---|
| 43 | threads->create(\&thread)->join();
|
|---|
| 44 |
|
|---|
| 45 | sub thread {
|
|---|
| 46 | eval "END { ok(1,'') }";
|
|---|
| 47 | threads->create(sub { eval "END { ok(1,'') }"})->join();
|
|---|
| 48 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.