Wasmtime with threads support, for easier porting of libraries

Porting C++ libraries that use threading is challenging, because the IC has turned off threads support in the wasmtime.

I get this error message when I compile my code using the experimental --target=wasm32-wasi-threads option of WebAssembly/wasi-sdk.

The wasm is properly build, but during dfx deploy I get:

Error: Failed while trying to deploy canisters.
Caused by: Failed while trying to deploy canisters.
  Failed while trying to install all canisters.
    Failed to install wasm module to canister 'greet'.
      Failed during wasm installation call: The replica returned a rejection error: reject code CanisterError, reject message Wasm module of canister bkyz2-fmaaa-aaaaa-qaaaq-cai is not valid: Wasmtime failed to validate wasm module wasmtime::Module::validate() failed with threads support is not enabled (at offset 0x346e9), error code None

I really plan to run on just one thread, but it is a lot of work to strip out all the threading code.

Any chance on turning threads support on for the IC canisters or perhaps do you have any other ideas?

Thank you!

2 Likes

Hey @icpp, we can’t just enable threads because ICP requires canister execution to be deterministic and introducing threading would lead to non-deterministic behavior.

The library has no support for building without threading?

1 Like

Thank you for that feedback and explaining the reason why it is turned off.

Unfortunately the library is not providing an option to build without threading, and I have seen that in other libraries as well.

I am currently investigating ways to implement stubs for pthread & mutex, and that way make it easier to convert those type of libraries.