Skip to content

Commit 7375e78

Browse files
authored
Fix default pthread stack size when running in worker. (#19577)
Fixes: #19573
1 parent 2c6d864 commit 7375e78

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/library_pthread.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#if BUILD_AS_WORKER
2020
#error "pthreads + BUILD_AS_WORKER require separate modes that don't work together, see https://github.com/emscripten-core/emscripten/issues/8854"
2121
#endif
22-
#if PROXY_TO_WORKER
23-
#error "--proxy-to-worker is not supported with -pthread! Use the option -sPROXY_TO_PTHREAD if you want to run the main thread of a multithreaded application in a web worker."
24-
#endif
2522
#if EVAL_CTORS
2623
#error "EVAL_CTORS is not compatible with pthreads yet (passive segments)"
2724
#endif

system/lib/pthread/emscripten_thread_init.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ void _emscripten_thread_init(pthread_t ptr,
1616
int default_stacksize,
1717
int start_profiling) {
1818
__set_thread_state(ptr, is_main, is_runtime, can_block);
19-
if (is_main && default_stacksize) {
19+
// Set `__default_stacksize` just once when the main runtime thread is
20+
// started. The value of `DEFAULT_PTHREAD_STACK_SIZE` is passed in here as
21+
// `default_stacksize`.
22+
if (is_runtime && default_stacksize) {
2023
__default_stacksize = default_stacksize;
2124
}
2225
#ifndef NDEBUG

test/other/test_default_pthread_stack_size.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ int main() {
1414
pthread_attr_getstacksize(&attr, &stacksize);
1515
printf("expected: %d, actual: %zu\n", EXPECTED_STACK_SIZE, stacksize);
1616
assert(stacksize == EXPECTED_STACK_SIZE);
17+
printf("done\n");
1718
return 0;
1819
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
done

test/test_other.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12366,11 +12366,15 @@ def test_default_pthread_stack_size(self):
1236612366

1236712367
# Same again with pthreads enabled
1236812368
self.setup_node_pthreads()
12369-
self.do_runf(test_file('other/test_default_pthread_stack_size.c'))
12369+
self.do_other_test('test_default_pthread_stack_size.c')
1237012370

1237112371
# Same again but with a custom stack size
1237212372
self.emcc_args += ['-DEXPECTED_STACK_SIZE=1024', '-sDEFAULT_PTHREAD_STACK_SIZE=1024']
12373-
self.do_runf(test_file('other/test_default_pthread_stack_size.c'))
12373+
self.do_other_test('test_default_pthread_stack_size.c')
12374+
12375+
# Same again but with a --proxy-to-worker
12376+
self.emcc_args += ['--proxy-to-worker']
12377+
self.do_other_test('test_default_pthread_stack_size.c')
1237412378

1237512379
def test_emscripten_set_immediate(self):
1237612380
self.do_runf(test_file('emscripten_set_immediate.c'))

0 commit comments

Comments
 (0)