Skip to content

Commit 15c8845

Browse files
committed
Set pthread stack size when -sSTACK_SIZE is set
This was always my intention with #18191 but somehow it got left out. I think it makes sense that user to override `STACK_SIZE` also, by default, override the pthread stack size. Such users can always explicitly set the pthread stack size if they don't want this behaviour. See #18472
1 parent 785bdd9 commit 15c8845

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.30 (in development)
2222
-----------------------
23+
- As a followup to #18191, the default pthread stack size will now be set to
24+
match `-sSTACK_SIZE` by default. Setting `DEFAULT_PTHREAD_STACK_SIZE`
25+
explicitly will override this.
2326
- The `buffer` JavaScript variable was removed. This underlying buffer is
2427
still accessible via `wasmMemory.buffer` or `HEAPXX.buffer`. In debug builds,
2528
a clear error is shown if you try to use it. (#18454)

emcc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,8 @@ def setup_pthreads(target):
16271627
if settings.ALLOW_MEMORY_GROWTH:
16281628
diagnostics.warning('pthreads-mem-growth', 'USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271')
16291629

1630+
default_setting('DEFAULT_PTHREAD_STACK_SIZE', settings.STACK_SIZE)
1631+
16301632
# Functions needs to be exported from the module since they are used in worker.js
16311633
settings.REQUIRED_EXPORTS += [
16321634
'emscripten_dispatch_to_thread_',

src/settings.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,18 +1581,14 @@ var PTHREAD_POOL_SIZE_STRICT = 1;
15811581
// [link] - affects generated JS runtime code at link time
15821582
var PTHREAD_POOL_DELAY_LOAD = false;
15831583

1584-
// If not explicitly specified, this is the stack size to use for newly created
1585-
// pthreads. According to
1586-
// http://man7.org/linux/man-pages/man3/pthread_create.3.html, default stack
1587-
// size on Linux/x86-32 for a new thread is 2 megabytes, so follow the same
1588-
// convention. Use pthread_attr_setstacksize() at thread creation time to
1589-
// explicitly specify the stack size, in which case this value is ignored. Note
1590-
// that the wasm function call control flow stack is separate from this
1591-
// stack, and this stack only contains certain function local variables, such as
1592-
// those that have their addresses taken, or ones that are too large to fit as
1593-
// local vars in wasm code.
1594-
// [link]
1595-
var DEFAULT_PTHREAD_STACK_SIZE = 64*1024;
1584+
// Default stack size to use for newly created pthreads. When not set, this
1585+
// defaults to STACK_SIZE (which in turn defaults to 64k). Can also be set at
1586+
// runtime using pthread_attr_setstacksize(). Note that the wasm control flow
1587+
// stack is separate from this stack. This stack only contains certain function
1588+
// local variables, such as those that have their addresses taken, or ones that
1589+
// are too large to fit as local vars in wasm code.
1590+
// [link]
1591+
var DEFAULT_PTHREAD_STACK_SIZE = 0;
15961592

15971593
// True when building with --threadprofiler
15981594
// [link]

0 commit comments

Comments
 (0)