Use newer 'threads' constructs
[p5sagit/p5-mst-13.2.git] / ext / XS / APItest / t / my_cxt.t
CommitLineData
85ce96a1 1#!perl -w
2
3# test per-interpeter static data API (MY_CXT)
4# DAPM Dec 2005
5
6my $threads;
7BEGIN {
8 chdir 't' if -d 't';
9 @INC = '../lib';
10 push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
11 require Config; import Config;
12 if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
13 # Look, I'm using this fully-qualified variable more than once!
14 my $arch = $MacPerl::Architecture;
15 print "1..0 # Skip: XS::APItest was not built\n";
16 exit 0;
17 }
18 $threads = $Config{'useithreads'};
19 # must 'use threads' before 'use Test::More'
20 eval 'use threads' if $threads;
21}
22
23use warnings;
24use strict;
25
26use Test::More tests => 11;
27
28BEGIN {
29 use_ok('XS::APItest');
30};
31
32is(my_cxt_getint(), 99, "initial int value");
33is(my_cxt_getsv(), "initial", "initial SV value");
34
35my_cxt_setint(1234);
36is(my_cxt_getint(), 1234, "new int value");
37
38my_cxt_setsv("abcd");
39is(my_cxt_getsv(), "abcd", "new SV value");
40
41sub do_thread {
42 is(my_cxt_getint(), 1234, "initial int value (child)");
43 my_cxt_setint(4321);
44 is(my_cxt_getint(), 4321, "new int value (child)");
45
46 is(my_cxt_getsv(), "initial_clone", "initial sv value (child)");
47 my_cxt_setsv("dcba");
48 is(my_cxt_getsv(), "dcba", "new SV value (child)");
49}
50
51SKIP: {
52 skip "No threads", 4 unless $threads;
878090d5 53 threads->create(\&do_thread)->join;
85ce96a1 54}
55
56is(my_cxt_getint(), 1234, "int value preserved after join");
57is(my_cxt_getsv(), "abcd", "SV value preserved after join");