Ooops. Not everybody does threads.
[p5sagit/p5-mst-13.2.git] / ext / threads / shared / t / sv_simple.t
CommitLineData
b050c948 1
2
3
4
5BEGIN {
6# chdir 't' if -d 't';
7# push @INC ,'../lib';
8 require Config; import Config;
9 unless ($Config{'useithreads'}) {
10 print "1..0 # Skip: no useithreads\n";
11 exit 0;
12 }
13}
14
15
16sub ok {
17 my ($id, $ok, $name) = @_;
18
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
27
28use ExtUtils::testlib;
29use strict;
30BEGIN { print "1..10\n" };
31use threads;
32use threads::shared;
33ok(1,1,"loaded");
34my $test = "bar";
35share($test);
36ok(2,$test eq "bar","Test magic share fetch");
37$test = "foo";
38ok(3,$test eq "foo","Test magic share assign");
6b85e4fe 39my $c = threads::shared::_refcnt($test);
b050c948 40threads->create(
41 sub {
a446a88f 42 ok(4, $test eq "foo","Test magic share fetch after thread");
b050c948 43 $test = "baz";
6b85e4fe 44 ok(5,threads::shared::_refcnt($test) > $c, "Check that threadcount is correct");
b050c948 45 })->join();
46ok(6,$test eq "baz","Test that value has changed in another thread");
6b85e4fe 47ok(7,threads::shared::_refcnt($test) == $c,"Check thrcnt is down properly");
b050c948 48$test = "barbar";
49ok(8, length($test) == 6, "Check length code");
50threads->create(sub { $test = "barbarbar" })->join;
51ok(9, length($test) == 9, "Check length code after different thread modified it");
52threads->create(sub { undef($test)})->join();
53ok(10, !defined($test), "Check undef value");
54
55
56
57
58
59
60