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