1#!perl -w
2
3# test per-interpreter static data API (MY_CXT)
4# DAPM Dec 2005
5
6my $threads;
7BEGIN {
8    require Config; import Config;
9    $threads = $Config{'useithreads'};
10    # must 'use threads' before 'use Test::More'
11    eval 'use threads' if $threads;
12}
13
14use warnings;
15use strict;
16
17use Test::More tests => 16;
18
19BEGIN {
20    use_ok('XS::APItest');
21};
22
23is(my_cxt_getint(), 99, "initial int value");
24is(my_cxt_getsv($_),  "initial", "initial SV value$_")
25    foreach '', ' (context arg)';
26
27my_cxt_setint(1234);
28is(my_cxt_getint(), 1234, "new int value");
29
30my_cxt_setsv("abcd");
31is(my_cxt_getsv($_),  "abcd", "new SV value$_")
32    foreach '', ' (context arg)';
33
34sub do_thread {
35    is(my_cxt_getint(), 1234, "initial int value (child)");
36    my_cxt_setint(4321);
37    is(my_cxt_getint(), 4321, "new int value (child)");
38
39    is(my_cxt_getsv($_), "initial_clone", "initial sv value (child)$_")
40	    foreach '', ' (context arg)';
41    my_cxt_setsv("dcba");
42    is(my_cxt_getsv($_),  "dcba", "new SV value (child)$_")
43	    foreach '', ' (context arg)';
44}
45
46SKIP: {
47    skip "No threads", 6 unless $threads;
48    threads->create(\&do_thread)->join;
49}
50
51is(my_cxt_getint(), 1234,  "int value preserved after join");
52is(my_cxt_getsv($_),  "abcd", "SV value preserved after join$_")
53        foreach '', ' (context arg)';
54