Skip to content
Latchkey

Emscripten "shared memory ... but ... not enabled" pthreads error in CI

A threaded Emscripten build produces a wasm module with shared memory, which requires the atomics and bulk-memory features. If the build flags or the consuming runtime do not enable them, link or instantiation fails.

What this error means

emcc fails with "shared memory is enabled, but ... atomics ... not enabled", or the module errors at runtime because the host did not enable threads features.

emscripten
wasm-ld: error: --shared-memory is disallowed by main.o because it was not compiled
with 'atomics' or 'bulk-memory' features
emcc: error: 'wasm-ld ...' failed (returned 1)

Common causes

Pthreads enabled without the matching wasm features

Using -pthread/-sUSE_PTHREADS makes memory shared, which needs atomics and bulk-memory. Mismatched flags across objects cause the link to reject shared memory.

A subset of objects compiled without -pthread

Mixing objects compiled with and without -pthread leaves some without the required features, so wasm-ld disallows shared memory.

How to fix it

Compile and link all objects with pthreads

  1. Pass -pthread to every compile and the link command.
  2. Set a pthread pool size so threads are available.
  3. Rebuild so all objects carry atomics and bulk-memory.
Terminal
emcc -pthread -sPTHREAD_POOL_SIZE=4 main.c worker.c -o app.js

Drop pthreads if threads are not needed

If the threaded path is unintended, remove the pthread flags so the module uses ordinary linear memory.

How to prevent it

  • Apply -pthread consistently to every compile and the link.
  • Keep the runtime configured to enable threads features.
  • Avoid mixing threaded and non-threaded objects in one module.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →