5 require Config; import Config;
6 unless ($Config{'useithreads'}) {
7 print "1..0 # Skip: no useithreads\n";
16 use Hash::Util 'lock_keys';
18 # Note that we can't use Test::More here, as we would need to
19 # call is() from within the DESTROY() function at global destruction time,
20 # and parts of Test::* may have already been freed by then
24 my $test : shared = 1;
27 my ($got, $want, $desc) = @_;
28 unless ($got eq $want) {
29 print "# EXPECTED: $want\n";
30 print "# GOT: $got\n";
33 print "ok $test - $desc\n";
39 # This tests for too much destruction
40 # which was caused by cloning stashes
41 # on join which led to double the dataspace
43 #########################
50 my ($package, $file, $line) = caller;
51 is(threads->tid(),$self->{tid},
52 "In destroy[$self->{tid}] it should be correct too" )
55 $foo = bless {tid => 0}, 'Foo';
56 my $bar = threads->create(sub {
57 is(threads->tid(),1, "And tid be 1 here");
65 # This tests whether we can call Config::myconfig after threads have been
66 # started (interpreter cloned). 5.8.1 and 5.8.2 contained a bug that would
67 # disallow that too be done, because an attempt was made to change a variable
68 # with the : unique attribute.
70 #########################
72 threads->new( sub {1} )->join;
73 my $not = eval { Config::myconfig() } ? '' : 'not ';
74 print "${not}ok $test - Are we able to call Config::myconfig after clone\n";
77 # bugid 24383 - :unique hashes weren't being made readonly on interpreter
78 # clone; check that they are.
80 our $unique_scalar : unique;
81 our @unique_array : unique;
82 our %unique_hash : unique;
85 eval { $unique_scalar = 1 };
86 print $@ =~ /read-only/ ? '' : 'not ', "ok $test - unique_scalar\n";
88 eval { $unique_array[0] = 1 };
89 print $@ =~ /read-only/ ? '' : 'not ', "ok $test - unique_array\n";
91 eval { $unique_hash{abc} = 1 };
92 print $@ =~ /disallowed/ ? '' : 'not ', "ok $test - unique_hash\n";
97 # bugid #24940 :unique should fail on my and sub declarations
99 for my $decl ('my $x : unique', 'sub foo : unique') {
102 /^The 'unique' attribute may only be applied to 'our' variables/
103 ? '' : 'not ', "ok $test - $decl\n";
108 # Returing a closure from a thread caused problems. If the last index in
109 # the anon sub's pad wasn't for a lexical, then a core dump could occur.
110 # Otherwise, there might be leaked scalars.
112 # XXX DAPM 9-Jan-04 - backed this out for now - returning a closure from a
113 # thread seems to crash win32
120 # my $string = threads->new(\&f)->join->();
121 # print $string eq 'foobar' ? '' : 'not ', "ok $test - returning closure\n";
124 # Nothing is checking that total keys gets cloned correctly.
127 is (keys %h, 2, "keys correct in parent");
129 my $child = threads->new(sub { return scalar keys %h })->join;
130 is ($child, 2, "keys correct in child");
135 is (keys %h, 1, "keys correct in parent with restricted hash");
137 $child = threads->new(sub { return scalar keys %h })->join;
138 is ($child, 1, "keys correct in child with restricted hash");