fix for ext/threads/t/problems.t failures
[p5sagit/p5-mst-13.2.git] / ext / threads / t / problems.t
CommitLineData
da46a8d0 1
2BEGIN {
3 chdir 't' if -d 't';
974ec8aa 4 push @INC, '../lib';
da46a8d0 5 require Config; import Config;
6 unless ($Config{'useithreads'}) {
7 print "1..0 # Skip: no useithreads\n";
8 exit 0;
9 }
10}
11
997c206d 12use warnings;
da46a8d0 13use strict;
14use threads;
15use threads::shared;
997c206d 16
17# Note that we can't use Test::More here, as we would need to
18# call is() from within the DESTROY() function at global destruction time,
19# and parts of Test::* may have already been freed by then
20
21print "1..4\n";
22
23my $test : shared = 1;
24
25sub is($$$) {
26 my ($got, $want, $desc) = @_;
27 unless ($got eq $want) {
28 print "# EXPECTED: $want\n";
29 print "# GOT: got\n";
30 print "not ";
31 }
32 print "ok $test - $desc\n";
33 $test++;
34}
da46a8d0 35
36
37#
38# This tests for too much destruction
39# which was caused by cloning stashes
40# on join which led to double the dataspace
41#
42#########################
43
44$|++;
da46a8d0 45
46{
da46a8d0 47 sub Foo::DESTROY {
48 my $self = shift;
49 my ($package, $file, $line) = caller;
997c206d 50 is(threads->tid(),$self->{tid},
51 "In destroy[$self->{tid}] it should be correct too" )
da46a8d0 52 }
53 my $foo;
54 $foo = bless {tid => 0}, 'Foo';
55 my $bar = threads->create(sub {
997c206d 56 is(threads->tid(),1, "And tid be 1 here");
da46a8d0 57 $foo->{tid} = 1;
58 return $foo;
59 })->join();
60 $bar->{tid} = 0;
da46a8d0 61}
621;