The threaded browser build (web/Dockerfile, ADR 64, ADR 66): the page may ask for fewer threads than the browser has cores, in the environment variable OPENSCAD_THREADS, which caps oneTBB for the whole run. --- a/src/main_wrapper.cc +++ b/src/main_wrapper.cc @@ -1,5 +1,13 @@ #include "openscad.h" +#ifdef __EMSCRIPTEN__ +#include +#include +#ifdef ENABLE_TBB +#include +#endif +#endif + #ifndef OPENSCAD_NOGUI #include // Bring in Q_INIT_RESOURCE #endif @@ -19,6 +27,15 @@ int main(int argc, char **argv) Q_INIT_RESOURCE(mac); #endif #endif +#if defined(__EMSCRIPTEN__) && defined(ENABLE_TBB) + // At most OPENSCAD_THREADS threads, where the page asks for fewer. + static std::optional threads; + if (const char *limit = std::getenv("OPENSCAD_THREADS")) { + if (const int n = std::atoi(limit); n > 0) { + threads.emplace(oneapi::tbb::global_control::max_allowed_parallelism, static_cast(n)); + } + } +#endif return openscad_main(argc, argv); }