Skip to content

Commit 516060b

Browse files
authored
Honor DEFAULT_PTHREAD_STACK_SIZE in pthread_attr_init (#19333)
Also remove the extra `_emscripten_default_pthread_stack_size` import/call in favor of just passing this information in during `_emscripten_thread_init`. Fixes: #19302, #15101
1 parent ab6e3ee commit 516060b

14 files changed

+32
-24
lines changed

emscripten.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ def create_wasm64_wrappers(metadata):
893893
'_emscripten_run_in_main_runtime_thread_js': '___p_',
894894
'_emscripten_proxy_execute_task_queue': '_p',
895895
'_emscripten_thread_exit': '_p',
896-
'_emscripten_thread_init': '_p____',
896+
'_emscripten_thread_init': '_p_____',
897897
'_emscripten_thread_free_data': '_p',
898898
'_emscripten_dlsync_self_async': '_p',
899899
'_emscripten_proxy_dlsync_async': '_pp',

src/library_pthread.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ var LibraryPThread = {
722722
/*isMainBrowserThread=*/!ENVIRONMENT_IS_WORKER,
723723
/*isMainRuntimeThread=*/1,
724724
/*canBlock=*/!ENVIRONMENT_IS_WEB,
725+
{{{ DEFAULT_PTHREAD_STACK_SIZE }}},
725726
#if PTHREADS_PROFILING
726727
/*start_profiling=*/true
727728
#endif
@@ -1042,12 +1043,6 @@ var LibraryPThread = {
10421043
return func.apply(null, emscripten_receive_on_main_thread_js_callArgs);
10431044
},
10441045

1045-
// TODO(sbc): Do we really need this to be dynamically settable from JS like this?
1046-
// See https://github.com/emscripten-core/emscripten/issues/15101.
1047-
_emscripten_default_pthread_stack_size: function() {
1048-
return {{{ DEFAULT_PTHREAD_STACK_SIZE }}};
1049-
},
1050-
10511046
#if STACK_OVERFLOW_CHECK >= 2 && MAIN_MODULE
10521047
$establishStackSpace__deps: ['$setDylinkStackLimits'],
10531048
#endif

src/library_sigs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ sigs = {
300300
_embind_register_void__sig: 'vpp',
301301
_emscripten_create_wasm_worker__sig: 'ipi',
302302
_emscripten_dbg__sig: 'vp',
303-
_emscripten_default_pthread_stack_size__sig: 'i',
304303
_emscripten_dlopen_js__sig: 'vpppp',
305304
_emscripten_dlsync_threads__sig: 'v',
306305
_emscripten_dlsync_threads_async__sig: 'vppp',

system/lib/pthread/emscripten_thread_init.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
#include <pthread.h>
88
#include "emscripten/threading.h"
99
#include "threading_internal.h"
10+
#include "pthread_impl.h"
1011

1112
void _emscripten_thread_init(pthread_t ptr,
1213
int is_main,
1314
int is_runtime,
1415
int can_block,
16+
int default_stacksize,
1517
int start_profiling) {
1618
__set_thread_state(ptr, is_main, is_runtime, can_block);
19+
if (is_main && default_stacksize) {
20+
__default_stacksize = default_stacksize;
21+
}
1722
#ifndef NDEBUG
1823
if (start_profiling) {
1924
_emscripten_thread_profiler_enable();

system/lib/pthread/library_pthread_stub.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,6 @@ int pthread_condattr_setpshared(pthread_condattr_t *attr, int shared) {
279279
return 0;
280280
}
281281

282-
int pthread_attr_init(pthread_attr_t *attr) {
283-
return 0;
284-
}
285-
286282
int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr) {
287283
return 0;
288284
}
@@ -389,6 +385,10 @@ void __lock(void* ptr) {}
389385

390386
void __unlock(void* ptr) {}
391387

388+
void __acquire_ptc() {}
389+
390+
void __release_ptc() {}
391+
392392
// When pthreads is not enabled, we can't use the Atomics futex api to do
393393
// proper sleeps, so simulate a busy spin wait loop instead.
394394
void emscripten_thread_sleep(double msecs) {

system/lib/pthread/pthread_create.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int __pthread_create(pthread_t* restrict res,
140140
pthread_attr_t attr = { 0 };
141141
if (attrp && attrp != __ATTRP_C11_THREAD) attr = *attrp;
142142
if (!attr._a_stacksize) {
143-
attr._a_stacksize = _emscripten_default_pthread_stack_size();
143+
attr._a_stacksize = __default_stacksize;
144144
}
145145

146146
// Allocate memory for new thread. The layout of the thread block is
@@ -149,7 +149,7 @@ int __pthread_create(pthread_t* restrict res,
149149
// 1. pthread struct (sizeof struct pthread)
150150
// 2. tls data (__builtin_wasm_tls_size())
151151
// 3. tsd pointers (__pthread_tsd_size)
152-
// 4. stack (_emscripten_default_pthread_stack_size())
152+
// 4. stack (__default_stacksize AKA -sDEFAULT_PTHREAD_STACK_SIZE)
153153
size_t size = sizeof(struct pthread);
154154
if (__builtin_wasm_tls_size()) {
155155
size += __builtin_wasm_tls_size() + __builtin_wasm_tls_align() - 1;

test/other/metadce/test_metadce_minimal_pthreads.exports

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ C
44
D
55
E
66
F
7-
G
7+
p
88
q
99
r
1010
s

test/other/metadce/test_metadce_minimal_pthreads.imports

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ a.l
1313
a.m
1414
a.n
1515
a.o
16-
a.p
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15448
1+
15425

test/other/metadce/test_metadce_minimal_pthreads.sent

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ l
1313
m
1414
n
1515
o
16-
p

0 commit comments

Comments
 (0)