Skip to content

Commit

Permalink
Set pthread stack size when -sSTACK_SIZE is set
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbc100 committed Jan 9, 2023
1 parent 785bdd9 commit 15c8845
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.

3.1.30 (in development)
-----------------------
- As a followup to #18191, the default pthread stack size will now be set to
match `-sSTACK_SIZE` by default. Setting `DEFAULT_PTHREAD_STACK_SIZE`
explicitly will override this.
- The `buffer` JavaScript variable was removed. This underlying buffer is
still accessible via `wasmMemory.buffer` or `HEAPXX.buffer`. In debug builds,
a clear error is shown if you try to use it. (#18454)
Expand Down
2 changes: 2 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,8 @@ def setup_pthreads(target):
if settings.ALLOW_MEMORY_GROWTH:
diagnostics.warning('pthreads-mem-growth', 'USE_PTHREADS + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271')

default_setting('DEFAULT_PTHREAD_STACK_SIZE', settings.STACK_SIZE)

# Functions needs to be exported from the module since they are used in worker.js
settings.REQUIRED_EXPORTS += [
'emscripten_dispatch_to_thread_',
Expand Down
20 changes: 8 additions & 12 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1581,18 +1581,14 @@ var PTHREAD_POOL_SIZE_STRICT = 1;
// [link] - affects generated JS runtime code at link time
var PTHREAD_POOL_DELAY_LOAD = false;

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

// True when building with --threadprofiler
// [link]
Expand Down

0 comments on commit 15c8845

Please sign in to comment.