Skip to content

WASI initialization in child thread #4102

Description

@toyobayashi

Details

wasi requires calling initialize() or start() after instantiating wasm and requires that memory is exported from wasm, but this doesn't work in multithreaded scenario (wasm32-wasi-threads target).

With wasi threads, we need to provide wasm memory created in JavaScript (new WebAssembly.Memory({ shared: true })) in main thread, and send the memory to child thread to instantiate wasm again in child thread, and it is unnecessary (and will cause error) to call initialize() or start() in child thread. So normal usage of WASI doesn't work in child thread. But we still need an "initialized" WASI instance in child thread.

Currently I'm using cloned instance object and Proxy to workaround this problem. Is there any possibility to handle this in future Node.js API change?

Node.js version

18.14.0

Example code

https://github.com/toyobayashi/emnapi/blob/9bc69c52bc8d582c92acc754ea6a0050572d871b/packages/core/src/load.js

loadNapiModuleImpl

Operating system

macOS 13.2

Scope

code? or runtime?

Module and version

require('node:wasi').WASI

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions