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