Fix mj_loadXML hang in single-threaded WASM builds
The top-level CMakeLists.txt unconditionally added -pthread for all Emscripten builds, but PTHREAD_POOL_SIZE was only set when MUJOCO_WASM_THREADS=ON. This gave the ST build a live pthread runtime with zero pre-spawned workers, causing CompileMeshesAndTextures to deadlock when it tried to spawn a ThreadPool on the main thread. Fix by making -pthread conditional on MUJOCO_WASM_THREADS. Without -pthread, hardware_concurrency() returns 0 and the existing nthread < 2 guards naturally select the serial compilation path. PiperOrigin-RevId: 900191420 Change-Id: I0481b81fc6f7cccb52c7d7592dcf9dd317b5bad1
This commit is contained in:
committed by
Copybara-Service
parent
e047f1101a
commit
7ac30a39fe
+6
-2
@@ -53,8 +53,12 @@ endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
option(MUJOCO_BUILD_TESTS_WASM "Build tests for WASM bindings" ON)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -O3 -pthread -fexceptions")
|
||||
option(MUJOCO_WASM_THREADS "Build with multi-threading support" ON)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -O3 -fexceptions")
|
||||
if(MUJOCO_WASM_THREADS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(APPLE AND (MUJOCO_BUILD_EXAMPLES OR MUJOCO_BUILD_SIMULATE))
|
||||
|
||||
@@ -31,8 +31,6 @@ if(NOT MUJOCO_WASM_FILES)
|
||||
message(FATAL_ERROR "No source files found in codegen/generated/")
|
||||
endif()
|
||||
|
||||
option(MUJOCO_WASM_THREADS "Build with multi-threading support" ON)
|
||||
|
||||
# Set Emscripten linker flags
|
||||
set(EMCC_LINKER_FLAGS
|
||||
"--bind"
|
||||
|
||||
Reference in New Issue
Block a user