This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wasm-micro-runtime/samples/wasi-threads
Wenyong Huang 38c67b3f48
thread-mgr: Fix spread "wasi proc exit" exception and atomic.wait issues (#1988)
Raising "wasi proc exit" exception, spreading it to other threads and then
clearing it in all threads may result in unexpected behavior: the sub thread
may end first, handle the "wasi proc exit" exception and clear exceptions
of other threads, including the main thread. And when main thread's
exception is cleared, it may continue to run and throw "unreachable"
exception. This also leads to some assertion failed.

Ignore exception spreading for "wasi proc exit" and don't clear exception
of other threads to resolve the issue.

And add suspend flag check after atomic wait since the atomic wait may
be notified by other thread when exception occurs.
2023-02-24 20:05:39 +08:00
..
wasm-apps thread-mgr: Fix spread "wasi proc exit" exception and atomic.wait issues (#1988) 2023-02-24 20:05:39 +08:00
CMakeLists.txt Create a placeholder for WASI threads implementation (#1783) 2022-12-06 21:11:27 +08:00
README.md thread-mgr: Fix spread "wasi proc exit" exception and atomic.wait issues (#1988) 2023-02-24 20:05:39 +08:00

"WASI threads" sample introduction

Currently, since the wasi-sdk does not have thread support in the latest release, make sure to have wasi-libc installed. Build it with threads enabled, e.g.

make \
    AR=/opt/wasi-sdk/bin/llvm-ar \
    NM=/opt/wasi-sdk/bin/llvm-nm \
    CC=/opt/wasi-sdk/bin/clang \
    THREAD_MODEL=posix

Build and run the samples

$ mkdir build
$ cd build
$ cmake -DWASI_SYSROOT=/path/to/wasi-libc/sysroot ..
$ make
...
$ ./iwasm wasm-apps/no_pthread.wasm
...
$ ./iwasm wasm-apps/exception_propagation.wasm

Run samples in AOT mode

$ ../../../wamr-compiler/build/wamrc \
    --enable-multi-thread \
    -o wasm-apps/no_pthread.aot wasm-apps/no_pthread.wasm
$ ./iwasm wasm-apps/no_pthread.aot