4 if( $ENV{PERL_CORE} ) {
14 # this is sucky because threads.pm has to be loaded before Test::Builder
16 eval { require Scalar::Util };
18 if ( $^O eq 'MSWin32' ) {
19 print "1..0 # Skip -- this test is generally broken on windows for unknown reasons. If you can help debug this patches would be very welcome.\n";
22 if ( $Config{usethreads} and !$Config{use5005threads}
23 and defined(&Scalar::Util::weaken)
24 and eval { require threads; threads->import; 1 }
28 print "1..0 # Skip -- threads aren't enabled in your perl, or Scalar::Util::weaken is missing\n";
37 print ( ( $_[0] ? "" : "not " ), "ok - $_[1]" );
41 print ( ( ( ($_[0]||'') eq ($_[1]||'') ) ? "" : "not "), "ok - $_[2]" );
44 tie my %hash, "Tie::RefHash";
52 $hash{$v1} = "string";
54 is( $hash{$v1}, "string", "fetch by string before clone ($v1)" );
55 is( $hash{$r1}, "hash", "fetch by ref before clone ($r1)" );
56 is( $hash{$r2}, "array", "fetch by ref before clone ($r2)" );
58 my $th = threads->create(sub {
59 is( scalar keys %hash, 3, "key count is OK" );
61 ok( exists $hash{$v1}, "string key exists ($v1)" );
62 is( $hash{$v1}, "string", "fetch by string" );
64 ok( exists $hash{$r1}, "ref key exists ($r1)" );
65 is( $hash{$r1}, "hash", "fetch by ref" );
67 ok( exists $hash{$r2}, "ref key exists ($r2)" );
68 is( $hash{$r2}, "array", "fetch by ref" );
70 is( join("\0",sort keys %hash), join("\0",sort $r1, $r2, $v1), "keys are ok" );
75 is( $hash{$v1}, "string", "fetch by string after clone, orig thread ($v1)" );
76 is( $hash{$r1}, "hash", "fetch by ref after clone ($r1)" );
77 is( $hash{$r2}, "array", "fetch by ref after clone ($r2)" );