wasix-org / wasix-libc

wasix libc implementation for WebAssembly
https://wasi.dev
Other
111 stars 19 forks source link

pthread_create returns EAGAIN #43

Open NEsanya opened 1 month ago

NEsanya commented 1 month ago

pthread_create returns EAGAIN.

Example:

#include <errno.h>
#include <pthread.h>
#include <stdio.h>

static void *simpleThreadHandler(void *data) {
  puts("meow");
  return NULL;
}

int main(int argc, char **argv) {
  pthread_t thread = {0};
  int code = pthread_create(&thread, NULL, simpleThreadHandler, NULL);
  if (code != 0) {
    switch (code) {
    case EAGAIN:
      fprintf(
          stderr,
          "Error while creating a thread: Resource temporarily unavailable\n");
      break;
    default:
      fprintf(stderr, "Error while creating a thread: %d\n", code);
      break;
    }
    return 1;
  }

  pthread_join(thread, NULL);

  return 0;
}

Building:

$ clang --sysroot=/usr/share/wasix-sysroot --target=wasm32-wasi main.c -o main.wasm -pthread -O2
$ wasmer main.wasm
Error while creating a thread: Resource temporarily unavailable

Versions & SHA256:

clang version 18.1.8 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /sbin Binary SHA256: d19e0263cd8e3d590d2faa8538641b2a0e3008522f016de22579c6e9b9002d95

wasix version v2024-07-08.1 sysroot.tar.gz SHA256: ab48114f09d6092eeab6752e50feaa34da8fe33112e02aadc81ea7e664ec7bd9 wasix-sysroot/lib/wasm32-wasi/libc.a SHA256: 00196f7b61519380e3b6c7cc84d1fb7772f2d73e581ddee9cbed37d9555e4585 wasix-sysroot/lib/wasm32-wasi/libpthread.a SHA256: f0a17a43c74d2fe5474fa2fd29c8f14799e777d7d75a2cc4d11c20a6e7b161c5