From 2b7fb32132070070e54658ec3d000cf5229401bb Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 15 Dec 2022 19:02:54 +0900 Subject: [PATCH 1/6] Add some concepts related to exit(3) * Introduce wasi_thread_exit * Introduce thread group and its exit status --- README.md | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73ea43b..0f56470 100644 --- a/README.md +++ b/README.md @@ -84,10 +84,11 @@ threads. ### API walk-through -The API consists of a single function. In pseudo-code: +The API consists of two functions. In pseudo-code: ```C status wasi_thread_spawn(thread_start_arg* start_arg); +void wasi_thread_exit(void); ``` where the `status` is a unique non-negative integer thread ID of the new @@ -172,6 +173,43 @@ TID is a 32-bit integer to identify threads created with `wasi_thread_spawn`. For example, it can be used to indicate the main thread, which doesn't have a TID in the current version of this proposal. +### Thread group + +* The main thread starts with a thread group which only contains + the main thread. + +* Threads created by a thread in a thread group using `wasi_thread_spawn` + is added to the thread group. + +* When a thread is terminated, it's removed from the thread group. + +### Voluntary thread termination + +A thread can terminate itself voluntarily, either by calling +`wasi_thread_exit`, or by returning from `wasi_thread_start`. + +### Changes to WASI `proc_exit` + +With this proposal, the `proc_exit` function takes extra responsibility +to terminate all threads in the thread group, not only the calling one. + +Any of threads in the thread group can call `proc_exit`. + +### Traps + +When a thread caused a trap, it terminates all threads in the thread group +similarly to `proc_exit`. + +### Thread group exit status + +If one or more threads call WASI `proc_exit` or raise a trap, +one of them is chosen by the runtime to represent the exit status +of the thread group. +It's non deterministic which one is chosen. + +If the thread group gets empty without involving `proc_exit` or a trap, +it's treated as if the last thread called `proc_exit` with exit code 0. + #### Design choice: pthreads One of the goals of this API is to be able to support `pthreads` for C compiled From ccc58119a6d934e65355b00d6e231a8272f12c86 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 16 Dec 2022 14:41:07 +0900 Subject: [PATCH 2/6] Rename thread group to process It's a more commen name and matches "proc" in `proc_exit`. --- README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0f56470..6b97f8b 100644 --- a/README.md +++ b/README.md @@ -173,15 +173,17 @@ TID is a 32-bit integer to identify threads created with `wasi_thread_spawn`. For example, it can be used to indicate the main thread, which doesn't have a TID in the current version of this proposal. -### Thread group +### Process -* The main thread starts with a thread group which only contains +* A process is a group of threads. + +* The main thread starts with a process which only contains the main thread. -* Threads created by a thread in a thread group using `wasi_thread_spawn` - is added to the thread group. +* Threads created by a thread in a process using `wasi_thread_spawn` + is added to the process. -* When a thread is terminated, it's removed from the thread group. +* When a thread is terminated, it's removed from the process. ### Voluntary thread termination @@ -191,23 +193,23 @@ A thread can terminate itself voluntarily, either by calling ### Changes to WASI `proc_exit` With this proposal, the `proc_exit` function takes extra responsibility -to terminate all threads in the thread group, not only the calling one. +to terminate all threads in the process, not only the calling one. -Any of threads in the thread group can call `proc_exit`. +Any of threads in the process can call `proc_exit`. ### Traps -When a thread caused a trap, it terminates all threads in the thread group +When a thread caused a trap, it terminates all threads in the process similarly to `proc_exit`. -### Thread group exit status +### Process exit status If one or more threads call WASI `proc_exit` or raise a trap, one of them is chosen by the runtime to represent the exit status -of the thread group. +of the process. It's non deterministic which one is chosen. -If the thread group gets empty without involving `proc_exit` or a trap, +If the process gets empty without involving `proc_exit` or a trap, it's treated as if the last thread called `proc_exit` with exit code 0. #### Design choice: pthreads From ec8172dbe61ebb929896d18323fa124ef03e9041 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 4 Jan 2023 12:23:10 +0900 Subject: [PATCH 3/6] Remove thread_exit for now --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6b97f8b..eb19d66 100644 --- a/README.md +++ b/README.md @@ -84,11 +84,10 @@ threads. ### API walk-through -The API consists of two functions. In pseudo-code: +The API consists of a single function. In pseudo-code: ```C status wasi_thread_spawn(thread_start_arg* start_arg); -void wasi_thread_exit(void); ``` where the `status` is a unique non-negative integer thread ID of the new @@ -187,8 +186,8 @@ TID is a 32-bit integer to identify threads created with `wasi_thread_spawn`. ### Voluntary thread termination -A thread can terminate itself voluntarily, either by calling -`wasi_thread_exit`, or by returning from `wasi_thread_start`. +A thread can terminate itself voluntarily by returning from +`wasi_thread_start`. ### Changes to WASI `proc_exit` From dc1ac30ded30b2470f8d05e892f93c1efd7f780a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 6 Jan 2023 18:13:01 +0900 Subject: [PATCH 4/6] try to make a sentence less odd --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb19d66..29f8da7 100644 --- a/README.md +++ b/README.md @@ -208,8 +208,9 @@ one of them is chosen by the runtime to represent the exit status of the process. It's non deterministic which one is chosen. -If the process gets empty without involving `proc_exit` or a trap, -it's treated as if the last thread called `proc_exit` with exit code 0. +If all the threads in the process have been terminated without calling +`proc_exit` or raising a trap, it's treated as if the last thread called +`proc_exit` with exit code 0. #### Design choice: pthreads From f74d69dbb91015f13ecbc5dd170d19afc9657100 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 11 Jan 2023 18:24:18 +0900 Subject: [PATCH 5/6] english improvements --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29f8da7..aa7d43d 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ TID is a 32-bit integer to identify threads created with `wasi_thread_spawn`. the main thread. * Threads created by a thread in a process using `wasi_thread_spawn` - is added to the process. + are added to the process. * When a thread is terminated, it's removed from the process. @@ -194,7 +194,7 @@ A thread can terminate itself voluntarily by returning from With this proposal, the `proc_exit` function takes extra responsibility to terminate all threads in the process, not only the calling one. -Any of threads in the process can call `proc_exit`. +Any of the threads in the process can call `proc_exit`. ### Traps From c732034d00a60bf56d6861bc88c937e0a16c7b1e Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 11 Jan 2023 21:26:30 +0900 Subject: [PATCH 6/6] english improvement --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index aa7d43d..7d69566 100644 --- a/README.md +++ b/README.md @@ -198,8 +198,7 @@ Any of the threads in the process can call `proc_exit`. ### Traps -When a thread caused a trap, it terminates all threads in the process -similarly to `proc_exit`. +When a trap occurs in any thread, the entire process is terminated. ### Process exit status