Description
I maintain a custom implementation of a WASI Host (https://github.com/microsoft/vscode-wasm) on top of the VS Code API. This enables running wasm-wasi binaries and provide them transparent access to the VS Code file system, the console or a terminal.
I was very excited when I saw that there is a pre-release for thread support and started to add thread support to VS Code's host implementation. I implemented the necessary wasi::thread-spawn
import however starting the thread fails with a runtime exception that looks like:
RuntimeError: null function or function signature mismatch
at __wasi_thread_start_C (0002bda6:0x67db)
at wasi_thread_start (0002bda6:0x7301)
at port.onmessage (threadWorker.js:1921:28)
The C program I compile looks like this (slightly modified version from (https://www.geeksforgeeks.org/multithreading-in-c/):
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> //Header file for sleep(). man 3 sleep for details.
#include <pthread.h>
// A normal C function that is executed as a thread
// when its name is specified in pthread_create()
void *myThreadFun(void *vargp)
{
sleep(1);
printf("Printing GeeksQuiz from Thread \n");
return NULL;
}
int main()
{
pthread_t thread_id;
printf("Before Thread\n");
int result = pthread_create(&thread_id, NULL, myThreadFun, NULL);
printf("Thread created with result: %i\n", result);
result = pthread_join(thread_id, NULL);
printf("Thread joined with result: %i\n", result);
printf("After Thread\n");
exit(0);
}
I compile the program to WASM using the following command:
~/bin/wasi-sdk-20.0+threads/bin/clang -Wl,--initial-memory=10485760 -matomics -mbulk-memory -pthread main.c -o ./out/main.wasm -L /home/dirkb/bin/wasi-sdk-20.0+threads/share/wasi-sysroot/lib/wasm32-wasi-threads
The exception happens on this WASI statement
call_indirect (param i32) (result i32)
A more detailed view in the debugger is:
Any idea what I do wrong?
From debugging it I am pretty sure that the tid
and the start_arg
pointer are correct.