Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some concepts related to exit(3) #17

Merged
merged 6 commits into from
Jan 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add some concepts related to exit(3)
* Introduce wasi_thread_exit

* Introduce thread group and its exit status
yamt committed Jan 4, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2b7fb32132070070e54658ec3d000cf5229401bb
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need a concept of thread group? Why not just say that wasi_thread_spawn creates new threads and wasi_thread_exit terminates the current thread?

The thread group concept seems like something fairly specific to linux and/or the world outside of the process.

If we do want to give a name the container of threads why not use the commonly used term "process"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just wanted a name for what wasi proc_exit terminates. the name "process" is fine for me too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i renamed it to process.


### 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again just not just drop the in the thread group part of this phrase.


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Process exit status ? This terminology makes sense to me and aligns with the proc_exit name (the proc here stands for process)


If one or more threads call WASI `proc_exit` or raise a trap,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it include calling it proc_exit from the main thread?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

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