Skip to content

Commit 31cba34

Browse files
committed
Add stack size parameter to nqp::newthread
Adds a stack size parameter to set the initial stack size of a new thread.
1 parent da96d39 commit 31cba34

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2845,7 +2845,7 @@ QAST::OperationsJAST.map_classlib_core_op('jvmgetproperties', $TYPE_OPS, 'jvmget
28452845
QAST::OperationsJAST.map_classlib_core_op('getrusage', $TYPE_OPS, 'getrusage', [$RT_OBJ], $RT_OBJ, :tc);
28462846

28472847
# thread related opcodes
2848-
QAST::OperationsJAST.map_classlib_core_op('newthread', $TYPE_OPS, 'newthread', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);
2848+
QAST::OperationsJAST.map_classlib_core_op('newthread', $TYPE_OPS, 'newthread', [$RT_OBJ, $RT_INT, $RT_INT], $RT_OBJ, :tc);
28492849
QAST::OperationsJAST.map_classlib_core_op('threadrun', $TYPE_OPS, 'threadrun', [$RT_OBJ], $RT_OBJ, :tc);
28502850
QAST::OperationsJAST.map_classlib_core_op('threadjoin', $TYPE_OPS, 'threadjoin', [$RT_OBJ], $RT_OBJ, :tc);
28512851
QAST::OperationsJAST.map_classlib_core_op('threadid', $TYPE_OPS, 'threadid', [$RT_OBJ], $RT_INT, :tc);

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5706,9 +5706,9 @@ public void run() {
57065706
invokeArgless(tc, code);
57075707
}
57085708
}
5709-
public static SixModelObject newthread(SixModelObject code, long appLifetime, ThreadContext tc) {
5709+
public static SixModelObject newthread(SixModelObject code, long appLifetime, long stackSize, ThreadContext tc) {
57105710
SixModelObject thread = tc.gc.Thread.st.REPR.allocate(tc, tc.gc.Thread.st);
5711-
((VMThreadInstance)thread).thread = new Thread(new CodeRunnable(tc.gc, thread, code));
5711+
((VMThreadInstance)thread).thread = new Thread(new CodeRunnable(tc.gc, thread, code, stackSize));
57125712
((VMThreadInstance)thread).thread.setDaemon(appLifetime != 0);
57135713
return thread;
57145714
}

t/concurrency/01-thread.t

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plan(24);
33
# 2 tests
44
{
55
my $ran := 0;
6-
my $t := nqp::newthread({ $ran := 1 }, 0);
6+
my $t := nqp::newthread({ $ran := 1 }, 0, 0);
77
ok(nqp::defined($t), 'Can create a new non-app-lifetime thread');
88
nqp::threadrun($t);
99
nqp::threadjoin($t);
@@ -13,7 +13,7 @@ plan(24);
1313
# 2 tests
1414
{
1515
my $start := nqp::time_n();
16-
my $t := nqp::newthread({ nqp::sleep(10.0) }, 1);
16+
my $t := nqp::newthread({ nqp::sleep(10.0) }, 1, 0);
1717
ok(nqp::defined($t), 'Can create a new app-lifetime thread');
1818
nqp::threadrun($t);
1919
ok(nqp::time_n() - $start < 10.0,
@@ -26,7 +26,7 @@ plan(24);
2626
my $t := nqp::newthread({
2727
1 until $done;
2828
ok(1, 'Can write to STDOUT in child thread');
29-
}, 0);
29+
}, 0, 0);
3030
ok(1, 'Can write to STDOUT in parent thread before threadrun');
3131
nqp::threadrun($t);
3232
ok(1, 'Can write to STDOUT in parent thread after threadrun');
@@ -45,7 +45,7 @@ plan(24);
4545
my $cid := 0;
4646
my $t := nqp::newthread({
4747
$cid := nqp::threadid(nqp::currentthread());
48-
}, 0);
48+
}, 0, 0);
4949
ok(nqp::defined($t), 'Can create another new thread after previous joins');
5050

5151
$tid := nqp::threadid($t);
@@ -69,8 +69,8 @@ plan(24);
6969
{
7070
my $a := 0;
7171
my $b := 0;
72-
my $t1 := nqp::newthread({ $a := 21 }, 0);
73-
my $t2 := nqp::newthread({ $b := 42 }, 0);
72+
my $t1 := nqp::newthread({ $a := 21 }, 0, 0);
73+
my $t2 := nqp::newthread({ $b := 42 }, 0, 0);
7474

7575
nqp::threadrun($t1);
7676
nqp::threadrun($t2);
@@ -96,7 +96,7 @@ plan(24);
9696
nqp::push(@a, '1');
9797
nqp::threadyield() until nqp::elems(@a) == 3 && @a[2] eq 'b';
9898
nqp::push(@a, '2');
99-
}, 0);
99+
}, 0, 0);
100100

101101
# Make sure child thread is at least *runnable* (if not actually running)
102102
# before running parent thread's code.
@@ -133,13 +133,13 @@ plan(24);
133133
nqp::push(@a, 'b');
134134
nqp::threadyield() until nqp::elems(@a) == 4 && @a[3] eq '2';
135135
nqp::push(@a, 'c');
136-
}, 0);
136+
}, 0, 0);
137137
my $t2 := nqp::newthread({
138138
nqp::threadyield() until nqp::elems(@a) == 1 && @a[0] eq 'a';
139139
nqp::push(@a, '1');
140140
nqp::threadyield() until nqp::elems(@a) == 3 && @a[2] eq 'b';
141141
nqp::push(@a, '2');
142-
}, 0);
142+
}, 0, 0);
143143

144144
# Make sure $t2 is at least *runnable* (if not actually running)
145145
# before $t1 becomes runnable.

t/concurrency/02-lock.t

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ my class CondVar is repr('ConditionVariable') { }
4545
nqp::lock($l);
4646
ok(1, 'Lock that survived CATCH works in another thread too');
4747
nqp::unlock($l);
48-
}, 0);
48+
}, 0, 0);
4949
nqp::threadrun($t);
5050
nqp::threadjoin($t);
5151

@@ -70,7 +70,7 @@ my class CondVar is repr('ConditionVariable') { }
7070
$output := $output ~ 'a';
7171
}
7272
nqp::unlock($l);
73-
}, 0);
73+
}, 0, 0);
7474

7575
my $t2 := nqp::newthread({
7676
nqp::lock($l);
@@ -79,7 +79,7 @@ my class CondVar is repr('ConditionVariable') { }
7979
$output := $output ~ 'b';
8080
}
8181
nqp::unlock($l);
82-
}, 0);
82+
}, 0, 0);
8383

8484
nqp::threadrun($t1);
8585
nqp::threadrun($t2);
@@ -111,7 +111,7 @@ my class CondVar is repr('ConditionVariable') { }
111111
nqp::condsignalall($c);
112112
$now1 := nqp::time_n();
113113
nqp::unlock($l);
114-
}, 0);
114+
}, 0, 0);
115115
nqp::threadrun($t1);
116116

117117
my $elems := 0;
@@ -130,7 +130,7 @@ my class CondVar is repr('ConditionVariable') { }
130130
}
131131
nqp::push(@log, 'lager');
132132
nqp::unlock($l);
133-
}, 0);
133+
}, 0, 0);
134134
nqp::threadrun($t2);
135135

136136
nqp::threadjoin($t1);
@@ -161,35 +161,35 @@ my class CondVar is repr('ConditionVariable') { }
161161
nqp::condsignalone($c1);
162162
nqp::condsignalall($c2);
163163
nqp::unlock($l);
164-
}, 0);
164+
}, 0, 0);
165165

166166
my $t2 := nqp::newthread({
167167
nqp::lock($l);
168168
nqp::condwait($c1);
169169
$count_one++;
170170
nqp::unlock($l);
171-
}, 0);
171+
}, 0, 0);
172172

173173
my $t3 := nqp::newthread({
174174
nqp::lock($l);
175175
nqp::condwait($c1);
176176
$count_one++;
177177
nqp::unlock($l);
178-
}, 0);
178+
}, 0, 0);
179179

180180
my $t4 := nqp::newthread({
181181
nqp::lock($l);
182182
nqp::condwait($c2);
183183
$count_all++;
184184
nqp::unlock($l);
185-
}, 0);
185+
}, 0, 0);
186186

187187
my $t5 := nqp::newthread({
188188
nqp::lock($l);
189189
nqp::condwait($c2);
190190
$count_all++;
191191
nqp::unlock($l);
192-
}, 0);
192+
}, 0, 0);
193193

194194
# Start all waiting threads
195195
nqp::threadrun($t2);

t/concurrency/03-semaphore.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,28 @@ my class Semaphore is repr('Semaphore') { }
3838
my $s := nqp::box_i(3, Semaphore);
3939
my $t1 := nqp::newthread({
4040
nqp::semacquire($s);
41-
}, 0);
41+
}, 0, 0);
4242
my $t2 := nqp::newthread({
4343
nqp::semacquire($s);
44-
}, 0);
44+
}, 0, 0);
4545
my $t3 := nqp::newthread({
4646
nqp::semacquire($s);
47-
}, 0);
47+
}, 0, 0);
4848
my $t4 := nqp::newthread({
4949
ok(!nqp::semtryacquire($s), 'Trying fourth acquire before release fails');
50-
}, 0);
50+
}, 0, 0);
5151
my $t5 := nqp::newthread({
5252
my $before := nqp::time_n();
5353
nqp::semacquire($s);
5454
my $after := nqp::time_n();
5555
ok($after - $before > 1.0, 'Fourth acquire blocks on empty semaphore');
5656
ok($released, 'Fourth acquire succeeds after release in other thread');
57-
}, 0);
57+
}, 0, 0);
5858
my $t6 := nqp::newthread({
5959
nqp::sleep(3.0);
6060
$released := 1;
6161
nqp::semrelease($s);
62-
}, 0);
62+
}, 0, 0);
6363

6464
# First, exhaust semaphore capacity
6565
nqp::threadrun($t1);

t/concurrency/04-osr-crash.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ my $t := nqp::newthread({
99
ok(1, "in thread");
1010
dec()
1111
}
12-
}, 1);
12+
}, 1, 0);
1313
nqp::threadrun($t);
1414
nqp::threadjoin($t);
1515
ok(1, "Thread with top level loop survived");

0 commit comments

Comments
 (0)