Skip to content

How can I use thread with emsdk and wamr #947

@xingkaiyu

Description

@xingkaiyu

I want to use c++ std::thread and atomic in wasm file but wasi does not support them yet.
So I want to try emsdk as I see your sample of tensorflow.
But I always get failed when I try my own code.
I used WAMR-12-30-2021 and have enable WAMR_BUILD_LIB_PTHREAD, WAMR_BUILD_LIBC_EMCC and WAMR_BUILD_LIBC_UVWASI when building linux wamr. And I removed open.o, mmap.o and munmap.o in emsdk's libc.a.
When building wasm app, I add -mbulk-memory, -matomics and other params almost like tf_lite.patch.
I got 6 when call pthread_create and got throw_system_error when use std::thread.
I also test EMCC_ONLY_FORCED_STDLIBS=1 and MALLOC="none". But will got "unlinked import function" error.
My code (including linux CMakelist.txt) is attached.
emcc_thread.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions