1b39c5158Smillertuse strict; 2b39c5158Smillertuse warnings; 3b39c5158Smillert 4b39c5158SmillertBEGIN { 5b39c5158Smillert use Config; 6b39c5158Smillert if (! $Config{'useithreads'}) { 7b39c5158Smillert print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); 8b39c5158Smillert exit(0); 9b39c5158Smillert } 10b39c5158Smillert} 11b39c5158Smillert 12b39c5158Smillertuse ExtUtils::testlib; 13b39c5158Smillert 14b39c5158Smillertsub ok { 15b39c5158Smillert my ($id, $ok, $name) = @_; 16b39c5158Smillert 17b39c5158Smillert # You have to do it this way or VMS will get confused. 18b39c5158Smillert if ($ok) { 19b39c5158Smillert print("ok $id - $name\n"); 20b39c5158Smillert } else { 21b39c5158Smillert print("not ok $id - $name\n"); 22b39c5158Smillert printf("# Failed test at line %d\n", (caller)[2]); 23b39c5158Smillert } 24b39c5158Smillert 25b39c5158Smillert return ($ok); 26b39c5158Smillert} 27b39c5158Smillert 28b39c5158SmillertBEGIN { 29b39c5158Smillert $| = 1; 30b39c5158Smillert print("1..21\n"); ### Number of tests that will be run ### 31b39c5158Smillert}; 32b39c5158Smillert 33b39c5158Smillertuse threads; 34b39c5158Smillertuse threads::shared; 35b39c5158Smillertok(1, 1, 'Loaded'); 36b39c5158Smillert 37b39c5158Smillert### Start of Testing ### 38b39c5158Smillert 39b39c5158Smillertmy $foo; 40b39c5158Smillertmy $bar = "foo"; 41b39c5158Smillertshare($foo); 42b39c5158Smillerteval { $foo = \$bar; }; 43b39c5158Smillertok(2,my $temp1 = $@ =~/^Invalid\b.*shared scalar/, "Wrong error message"); 44b39c5158Smillert 45b39c5158Smillertshare($bar); 46b39c5158Smillert$foo = \$bar; 47b39c5158Smillertok(3, $temp1 = $foo =~/SCALAR/, "Check that is a ref"); 48b39c5158Smillertok(4, $$foo eq "foo", "Check that it points to the correct value"); 49b39c5158Smillert$bar = "yeah"; 50b39c5158Smillertok(5, $$foo eq "yeah", "Check that assignment works"); 51b39c5158Smillert$$foo = "yeah2"; 52b39c5158Smillertok(6, $$foo eq "yeah2", "Check that deref assignment works"); 53b39c5158Smillertthreads->create(sub {$bar = "yeah3"})->join(); 54*898184e3Ssthenok(7, $$foo eq "yeah3", "Check that other thread assignment works"); 55b39c5158Smillertthreads->create(sub {$foo = "artur"})->join(); 56b39c5158Smillertok(8, $foo eq "artur", "Check that uncopupling the ref works"); 57b39c5158Smillertmy $baz; 58b39c5158Smillertshare($baz); 59b39c5158Smillert$baz = "original"; 60b39c5158Smillert$bar = \$baz; 61b39c5158Smillert$foo = \$bar; 62b39c5158Smillertok(9,$$$foo eq 'original', "Check reference chain"); 63b39c5158Smillertmy($t1,$t2); 64b39c5158Smillertshare($t1); 65b39c5158Smillertshare($t2); 66b39c5158Smillert$t2 = "text"; 67b39c5158Smillert$t1 = \$t2; 68b39c5158Smillertthreads->create(sub { $t1 = "bar" })->join(); 69b39c5158Smillertok(10,$t1 eq 'bar',"Check that assign to a ROK works"); 70b39c5158Smillert 71b39c5158Smillertok(11, is_shared($foo), "Check for sharing"); 72b39c5158Smillert 73b39c5158Smillert{ 74b39c5158Smillert # Circular references with 3 shared scalars 75b39c5158Smillert my $x : shared; 76b39c5158Smillert my $y : shared; 77b39c5158Smillert my $z : shared; 78b39c5158Smillert 79b39c5158Smillert $x = \$y; 80b39c5158Smillert $y = \$z; 81b39c5158Smillert $z = \$x; 82b39c5158Smillert ok(12, ref($x) eq 'REF', '$x ref type'); 83b39c5158Smillert ok(13, ref($y) eq 'REF', '$y ref type'); 84b39c5158Smillert ok(14, ref($z) eq 'REF', '$z ref type'); 85b39c5158Smillert 86b39c5158Smillert my @q :shared = ($x); 87b39c5158Smillert ok(15, ref($q[0]) eq 'REF', '$q[0] ref type'); 88b39c5158Smillert 89b39c5158Smillert my $w = $q[0]; 90b39c5158Smillert ok(16, ref($w) eq 'REF', '$w ref type'); 91b39c5158Smillert ok(17, ref($$w) eq 'REF', '$$w ref type'); 92b39c5158Smillert ok(18, ref($$$w) eq 'REF', '$$$w ref type'); 93b39c5158Smillert ok(19, ref($$$$w) eq 'REF', '$$$$w ref type'); 94b39c5158Smillert 95b39c5158Smillert ok(20, is_shared($x) == is_shared($w), '_id($x) == _id($w)'); 96b39c5158Smillert ok(21, is_shared($w) == is_shared($$$$w), '_id($w) == _id($$$$w)'); 97b39c5158Smillert} 98b39c5158Smillert 99b39c5158Smillertexit(0); 100b39c5158Smillert 101b39c5158Smillert# EOF 102