emscripten-core / emscripten-core/emscripten

ALLOW_BLOCKING_ON_MAIN_THREAD=0 works differently on Mac and Linux

Open
#20,552 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Please include the following in your bug report:

**Version of emscripten/emsdk:**

```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.46-git
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 75501f53624de92aafce2f1da698b249a7293dc7)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.46/libexec/llvm/bin
```

**Full link command and output with `-v` appended:**

```
emcc -Llib -pthread -s EXPORTED_RUNTIME_METHODS=["cwrap","stringToNewUTF8","UTF8ToString"] -s EXPORTED_FUNCTIONS=_free,_main,_malloc,_precache_file_data,_process_ucgi_command_wasm,_score_play,_destroy_cache,_ucgi_search_status_wasm,_ucgi_stop_search_wasm,_static_evaluation -sPTHREAD_POOL_SIZE="navigator.hardwareConcurrency + 3" -s ALLOW_BLOCKING_ON_MAIN_THREAD=0 -v obj/src/anchor.o obj/src/autoplay.o obj/src/bag.o obj/src/board.o obj/src/config.o obj/src/cross_set.o obj/src/fileproxy.o obj/src/game.o obj/src/game_event.o obj/src/game_history.o obj/src/gameplay.o obj/src/gcg.o obj/src/go_params.o obj/src/infer.o obj/src/klv.o obj/src/kwg.o obj/src/leave_map.o obj/src/leave_rack.o obj/src/letter_distribution.o obj/src/log.o obj/src/move.o obj/src/movegen.o obj/src/player.o obj/src/rack.o obj/src/random.o obj/src/sim.o obj/src/stats.o obj/src/string_util.o obj/src/thread_control.o obj/src/ucgi.o obj/src/ucgi_command.o obj/src/ucgi_formats.o obj/src/ucgi_print.o obj/src/util.o obj/src/wasm_api.o obj/src/winpct.o obj/src/words.o obj/src/xoshiro.o obj/wasmentry/api.o -lm -o bin/magpie_shell.html \
-s INITIAL_MEMORY=128MB \
--shell-file wasm_shell.html
"/opt/homebrew/Cellar/emscripten/3.1.46/libexec/llvm/bin/clang" --version
"/opt/homebrew/Cellar/emscripten/3.1.46/libexec/llvm/bin/wasm-ld" -o bin/magpie_shell.wasm -Llib obj/src/anchor.o obj/src/autoplay.o obj/src/bag.o obj/src/board.o obj/src/config.o obj/src/cross_set.o obj/src/fileproxy.o obj/src/game.o obj/src/game_event.o obj/src/game_history.o obj/src/gameplay.o obj/src/gcg.o obj/src/go_params.o obj/src/infer.o obj/src/klv.o obj/src/kwg.o obj/src/leave_map.o obj/src/leave_rack.o obj/src/letter_distribution.o obj/src/log.o obj/src/move.o obj/src/movegen.o obj/src/player.o obj/src/rack.o obj/src/random.o obj/src/sim.o obj/src/stats.o obj/src/string_util.o obj/src/thread_control.o obj/src/ucgi.o obj/src/ucgi_command.o obj/src/ucgi_formats.o obj/src/ucgi_print.o obj/src/util.o obj/src/wasm_api.o obj/src/winpct.o obj/src/words.o obj/src/xoshiro.o obj/wasmentry/api.o -L/opt/homebrew/Cellar/emscripten/3.1.46/libexec/cache/sysroot/lib/wasm32-emscripten /opt/homebrew/Cellar/emscripten/3.1.46/libexec/cache/sysroot/lib/wasm32-emscripten/crtbegin.o -lGL-mt -lal -lhtml5 -lbulkmemory -lstubs-debug -lnoexit -lc-mt-debug -ldlmalloc-mt -lcompiler_rt-mt -lc++-mt-noexcept -lc++abi-debug-mt-noexcept -lsockets-mt -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/jy/zkj5g46j1dzf8304s7ybvny40000gn/T/tmp__30ovonlibemscripten_js_symbols.so --import-memory --shared-memory --strip-debug --export-if-defined=free --export-if-defined=main --export-if-defined=malloc --export-if-defined=precache_file_data --export-if-defined=process_ucgi_command_wasm --export-if-defined=score_play --export-if-defined=destroy_cache --export-if-defined=ucgi_search_status_wasm --export-if-defined=ucgi_stop_search_wasm --export-if-defined=static_evaluation --export-if-defined=_emscripten_thread_init --export-if-defined=_emscripten_thread_exit --export-if-defined=_emscripten_thread_crashed --export-if-defined=_emscripten_tls_init --export-if-defined=pthread_self --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=_emscripten_thread_free_data --export=emscripten_main_runtime_thread_id --export=emscripten_main_thread_process_queued_calls --export=_emscripten_run_on_main_thread_js --export=emscripten_stack_set_limits --export=__get_temp_ret --export=__set_temp_ret --export=__wasm_call_ctors --export=_emscripten_thread_init --export=_emscripten_thread_exit --export=malloc --export-table -z stack-size=65536 --initial-memory=134217728 --max-memory=134217728 --no-entry --stack-first --table-base=1
"/opt/homebrew/Cellar/emscripten/3.1.46/libexec/llvm/bin/llvm-objcopy" bin/magpie_shell.wasm bin/magpie_shell.wasm --remove-section=.debug* --remove-section=producers
"/opt/homebrew/Cellar/emscripten/3.1.46/libexec/binaryen/bin/wasm-emscripten-finalize" --dyncalls-i64 --pass-arg=legalize-js-interface-exported-helpers bin/magpie_shell.wasm -o bin/magpie_shell.wasm --detect-features
"/opt/homebrew/opt/node/bin/node" /opt/homebrew/Cellar/emscripten/3.1.46/libexec/src/compiler.js /var/folders/jy/zkj5g46j1dzf8304s7ybvny40000gn/T/tmpqm_4kdez.json
"/opt/homebrew/opt/node/bin/node" /opt/homebrew/Cellar/emscripten/3.1.46/libexec/tools/preprocessor.js /var/folders/jy/zkj5g46j1dzf8304s7ybvny40000gn/T/emscripten_temp_iou3le6h/settings.js worker.js --expandMacros
"/opt/homebrew/opt/node/bin/node" /opt/homebrew/Cellar/emscripten/3.1.46/libexec/tools/preprocessor.js /var/folders/jy/zkj5g46j1dzf8304s7ybvny40000gn/T/emscripten_temp_iou3le6h/settings.js wasm_shell.html
```

-------

I have a program where the main thread does not block; it exits immediately. When invoked from JS, a function creates a pthread and detaches immediately, thus not blocking. On Linux, the generated html shell works as designed. When compiled with the same version of emcc on Mac, with the same exact flags/code/Makefile/etc, the program prints "Blocking on the main thread is very dangerous" on the JS console and aborts.

Screenshot 2023-10-26 at 10 26 11 PM

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.