This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[ANNOUNCE] Math::BigInt v1.69
[perl5.git] / ext / threads / shared / t / no_share.t
CommitLineData
13c1b207
DM
1use warnings;
2
dab065ea
AB
3BEGIN {
4# chdir 't' if -d 't';
5# push @INC ,'../lib';
6 require Config; import Config;
7 unless ($Config{'useithreads'}) {
8 print "1..0 # Skip: no useithreads\n";
9 exit 0;
10 }
11 $SIG{__WARN__} = sub { $warnmsg = shift; };
12}
13
14
15sub ok {
16 my ($id, $ok, $name) = @_;
17
13c1b207 18 $name = '' unless defined $name;
dab065ea
AB
19 # You have to do it this way or VMS will get confused.
20 print $ok ? "ok $id - $name\n" : "not ok $id - $name\n";
21
22 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
23
24 return $ok;
25}
26
27our $warnmsg;
28use ExtUtils::testlib;
29use strict;
30BEGIN { print "1..5\n" };
31use threads::shared;
32use threads;
33ok(1,1,"loaded");
34ok(2,$warnmsg =~ /Warning, threads::shared has already been loaded/,
9c4972d9 35 "threads has warned us");
dab065ea
AB
36my $test = "bar";
37share($test);
38ok(3,$test eq "bar","Test disabled share not interfering");
39threads->create(
40 sub {
41 ok(4,$test eq "bar","Test disabled share after thread");
42 $test = "baz";
43 })->join();
9c4972d9
NIS
44# Value should either remain unchanged or be value set by other thread
45ok(5,$test eq "bar" || $test eq 'baz',"Test that value is an expected one");
46
dab065ea 47