threads 1.36 - Signalling terminated threads core dumps
[p5sagit/p5-mst-13.2.git] / ext / threads / t / stack.t
CommitLineData
514612b7 1use strict;
2use warnings;
3
4BEGIN {
5 if ($ENV{'PERL_CORE'}){
6 chdir 't';
7 unshift @INC, '../lib';
8 }
9 use Config;
10 if (! $Config{'useithreads'}) {
11 print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
12 exit(0);
13 }
14}
15
16use ExtUtils::testlib;
17
18sub ok {
19 my ($id, $ok, $name) = @_;
20
21 # You have to do it this way or VMS will get confused.
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 }
28
29 return ($ok);
30}
31
32BEGIN {
33 $| = 1;
34 print("1..18\n"); ### Number of tests that will be run ###
35};
36
37use threads 1.09 ('stack_size' => 32*4096);
38ok(1, 1, 'Loaded');
39
40### Start of Testing ###
41
42ok(2, threads->get_stack_size() == 32*4096,
43 'Stack size set in import');
44ok(3, threads->set_stack_size(64*4096) == 32*4096,
45 'Set returns previous value');
46ok(4, threads->get_stack_size() == 64*4096,
47 'Get stack size');
48
49threads->create(
50 sub {
51 ok(5, threads->get_stack_size() == 64*4096,
52 'Get stack size in thread');
53 ok(6, threads->self()->get_stack_size() == 64*4096,
54 'Thread gets own stack size');
55 ok(7, threads->set_stack_size(32*4096) == 64*4096,
56 'Thread changes stack size');
57 ok(8, threads->get_stack_size() == 32*4096,
58 'Get stack size in thread');
59 ok(9, threads->self()->get_stack_size() == 64*4096,
60 'Thread stack size unchanged');
61 }
62)->join();
63
64ok(10, threads->get_stack_size() == 32*4096,
65 'Default thread sized changed in thread');
66
67threads->create(
68 { 'stack' => 64*4096 },
69 sub {
70 ok(11, threads->get_stack_size() == 32*4096,
71 'Get stack size in thread');
72 ok(12, threads->self()->get_stack_size() == 64*4096,
73 'Thread gets own stack size');
74 }
75)->join();
76
77my $thr = threads->create( { 'stack' => 64*4096 }, sub { } );
78
79$thr->create(
80 sub {
81 ok(13, threads->get_stack_size() == 32*4096,
82 'Get stack size in thread');
83 ok(14, threads->self()->get_stack_size() == 64*4096,
84 'Thread gets own stack size');
85 }
86)->join();
87
88$thr->create(
89 { 'stack' => 48*4096 },
90 sub {
91 ok(15, threads->get_stack_size() == 32*4096,
92 'Get stack size in thread');
93 ok(16, threads->self()->get_stack_size() == 48*4096,
94 'Thread gets own stack size');
95 ok(17, threads->set_stack_size(64*4096) == 32*4096,
96 'Thread changes stack size');
97 }
98)->join();
99
100$thr->join();
101
102ok(18, threads->get_stack_size() == 64*4096,
103 'Default thread sized changed in thread');
104
105# EOF