| 1 |
#!perl -w |
| 2 |
|
| 3 |
# test per-interpreter static data API (MY_CXT) |
| 4 |
# DAPM Dec 2005 |
| 5 |
|
| 6 |
my $threads; |
| 7 |
BEGIN { |
| 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 |
|
| 14 |
use warnings; |
| 15 |
use strict; |
| 16 |
|
| 17 |
use Test::More tests => 16; |
| 18 |
|
| 19 |
BEGIN { |
| 20 |
use_ok('XS::APItest'); |
| 21 |
}; |
| 22 |
|
| 23 |
is(my_cxt_getint(), 99, "initial int value"); |
| 24 |
is(my_cxt_getsv($_), "initial", "initial SV value$_") |
| 25 |
foreach '', ' (context arg)'; |
| 26 |
|
| 27 |
my_cxt_setint(1234); |
| 28 |
is(my_cxt_getint(), 1234, "new int value"); |
| 29 |
|
| 30 |
my_cxt_setsv("abcd"); |
| 31 |
is(my_cxt_getsv($_), "abcd", "new SV value$_") |
| 32 |
foreach '', ' (context arg)'; |
| 33 |
|
| 34 |
sub 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 |
|
| 46 |
SKIP: { |
| 47 |
skip "No threads", 6 unless $threads; |
| 48 |
threads->create(\&do_thread)->join; |
| 49 |
} |
| 50 |
|
| 51 |
is(my_cxt_getint(), 1234, "int value preserved after join"); |
| 52 |
is(my_cxt_getsv($_), "abcd", "SV value preserved after join$_") |
| 53 |
foreach '', ' (context arg)'; |