Fix atomic.wait, get wasi_ctx exit code and thread mgr issues (#2024)
- Remove notify_stale_threads_on_exception and change atomic.wait to be interruptible by keep waiting and checking every one second, like the implementation of poll_oneoff in libc-wasi - Wait all other threads exit and then get wasi exit_code to avoid getting invalid value - Inherit suspend_flags of parent thread while creating new thread to avoid terminated flag isn't set for new thread - Fix wasi-threads test case update_shared_data_and_alloc_heap - Add "Lib wasi-threads enabled" prompt for cmake - Fix aot get exception, use aot_copy_exception instead
This commit is contained in:
@ -41,9 +41,6 @@ __wasi_thread_start_C(int thread_id, int *start_arg)
|
||||
for (int i = 0; i < NUM_ITER; i++)
|
||||
__atomic_fetch_add(data->count, 1, __ATOMIC_SEQ_CST);
|
||||
|
||||
pthread_mutex_lock(&mutex); /* malloc is not thread-safe in wasi-libc */
|
||||
vals[data->iteration] = malloc(sizeof(int));
|
||||
pthread_mutex_unlock(&mutex);
|
||||
*vals[data->iteration] = data->iteration;
|
||||
|
||||
__atomic_store_n(&data->th_done, 1, __ATOMIC_SEQ_CST);
|
||||
@ -60,6 +57,11 @@ main(int argc, char **argv)
|
||||
assert(count != NULL && "Failed to call calloc");
|
||||
assert(pthread_mutex_init(&mutex, NULL) == 0 && "Failed to init mutex");
|
||||
|
||||
for (int i = 0; i < NUM_THREADS; i++) {
|
||||
vals[i] = malloc(sizeof(int));
|
||||
assert(vals[i] != NULL && "Failed to call calloc");
|
||||
}
|
||||
|
||||
for (int i = 0; i < NUM_THREADS; i++) {
|
||||
assert(start_args_init(&data[i].base)
|
||||
&& "Stack allocation for thread failed");
|
||||
|
||||
@ -525,6 +525,9 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
|
||||
goto fail4;
|
||||
}
|
||||
|
||||
/* Inherit suspend_flags of parent thread */
|
||||
new_exec_env->suspend_flags.flags = exec_env->suspend_flags.flags;
|
||||
|
||||
if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
|
||||
goto fail4;
|
||||
|
||||
@ -674,6 +677,9 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
|
||||
new_exec_env->aux_stack_bottom.bottom = UINT32_MAX;
|
||||
}
|
||||
|
||||
/* Inherit suspend_flags of parent thread */
|
||||
new_exec_env->suspend_flags.flags = exec_env->suspend_flags.flags;
|
||||
|
||||
if (!wasm_cluster_add_exec_env(cluster, new_exec_env))
|
||||
goto fail3;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user