1use strict; 2use warnings; 3 4BEGIN { 5 use Config; 6 if (! $Config{'useithreads'}) { 7 print("1..0 # SKIP Perl not compiled with 'useithreads'\n"); 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 33use threads ('stack_size' => 128*4096); 34ok(1, 1, 'Loaded'); 35 36### Start of Testing ### 37 38ok(2, threads->get_stack_size() == 128*4096, 39 'Stack size set in import'); 40ok(3, threads->set_stack_size(160*4096) == 128*4096, 41 'Set returns previous value'); 42ok(4, threads->get_stack_size() == 160*4096, 43 'Get stack size'); 44 45threads->create( 46 sub { 47 ok(5, threads->get_stack_size() == 160*4096, 48 'Get stack size in thread'); 49 ok(6, threads->self()->get_stack_size() == 160*4096, 50 'Thread gets own stack size'); 51 ok(7, threads->set_stack_size(128*4096) == 160*4096, 52 'Thread changes stack size'); 53 ok(8, threads->get_stack_size() == 128*4096, 54 'Get stack size in thread'); 55 ok(9, threads->self()->get_stack_size() == 160*4096, 56 'Thread stack size unchanged'); 57 } 58)->join(); 59 60ok(10, threads->get_stack_size() == 128*4096, 61 'Default thread sized changed in thread'); 62 63threads->create( 64 { 'stack' => 160*4096 }, 65 sub { 66 ok(11, threads->get_stack_size() == 128*4096, 67 'Get stack size in thread'); 68 ok(12, threads->self()->get_stack_size() == 160*4096, 69 'Thread gets own stack size'); 70 } 71)->join(); 72 73my $thr = threads->create( { 'stack' => 160*4096 }, sub { } ); 74 75$thr->create( 76 sub { 77 ok(13, threads->get_stack_size() == 128*4096, 78 'Get stack size in thread'); 79 ok(14, threads->self()->get_stack_size() == 160*4096, 80 'Thread gets own stack size'); 81 } 82)->join(); 83 84$thr->create( 85 { 'stack' => 144*4096 }, 86 sub { 87 ok(15, threads->get_stack_size() == 128*4096, 88 'Get stack size in thread'); 89 ok(16, threads->self()->get_stack_size() == 144*4096, 90 'Thread gets own stack size'); 91 ok(17, threads->set_stack_size(160*4096) == 128*4096, 92 'Thread changes stack size'); 93 } 94)->join(); 95 96$thr->join(); 97 98ok(18, threads->get_stack_size() == 160*4096, 99 'Default thread sized changed in thread'); 100 101exit(0); 102 103# EOF 104