1use strict; 2use warnings; 3 4BEGIN { 5 use Config; 6 if (! $Config{'useithreads'}) { 7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); 8 exit(0); 9 } 10} 11 12use ExtUtils::testlib; 13 14sub ok { 15 my ($id, $ok, $name) = @_; 16 17 # You have to do it this way or VMS will get confused. 18 if ($ok) { 19 print("ok $id - $name\n"); 20 } else { 21 print("not ok $id - $name\n"); 22 printf("# Failed test at line %d\n", (caller)[2]); 23 } 24 25 return ($ok); 26} 27 28BEGIN { 29 $| = 1; 30 print("1..6\n"); ### Number of tests that will be run ### 31}; 32 33our $warnmsg; 34BEGIN { 35 $SIG{__WARN__} = sub { $warnmsg = shift; }; 36} 37 38use threads::shared; 39use threads; 40ok(1, 1, 'Loaded'); 41 42### Start of Testing ### 43 44ok(2, ($warnmsg =~ /Warning, threads::shared has already been loaded/)?1:0, 45 "threads has warned us"); 46 47my $test = "bar"; 48share($test); 49ok(3, $test eq "bar", "Test disabled share not interfering"); 50 51threads->create(sub { 52 ok(4, $test eq "bar", "Test disabled share after thread"); 53 $test = "baz"; 54 })->join(); 55# Value should either remain unchanged or be value set by other thread 56ok(5, $test eq "bar" || $test eq 'baz', "Test that value is an expected one"); 57 58ok(6, ! is_shared($test), "Check for sharing"); 59 60exit(0); 61 62# EOF 63