Skip to content

__init_tp: Initialize TID to non-zero value#360

Merged
abrown merged 1 commit intoWebAssembly:mainfrom
yamt:tid
Jan 6, 2023
Merged

__init_tp: Initialize TID to non-zero value#360
abrown merged 1 commit intoWebAssembly:mainfrom
yamt:tid

Conversation

@yamt
Copy link
Contributor

@yamt yamt commented Dec 13, 2022

__init_tp: Initialize TID to non-zero value

This fixes TID-based locking used within libc.

Also, initialize detach_state.

cf. WebAssembly/wasi-threads#16

* - __lockfile relies on the fact the most significant two bits
* of TIDs are 0.
*/
td->tid = 0x3fffffff;
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialize the TID to a large value, which is hopefully
less likely to conflict with host-allocated TIDs

So, that assumption is correct only if the host assigns the ID incrementally, which might not be the case (host can decide the implementation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initialize the TID to a large value, which is hopefully
less likely to conflict with host-allocated TIDs

So, that assumption is correct only if the host assigns the ID incrementally, which might not be the case (host can decide the implementation).

right. this is a kludge at best.

i think a real fix involves spec changes. see WebAssembly/wasi-threads#15

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest let's wait with this PR then until the WebAssembly/wasi-threads#15 is resolved

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can update the PR based on the discussion in WebAssembly/wasi-threads#15 @yamt ?

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 think we can update the PR based on the discussion in WebAssembly/wasi-threads#15 @yamt ?

done

This fixes TID-based locking used within libc.

Also, initialize detach_state.

cf. WebAssembly/wasi-threads#16
@yamt yamt changed the title __init_tp: Workaround TID issue __init_tp: Initialize TID to non-zero value Jan 4, 2023
@yamt
Copy link
Contributor Author

yamt commented Jan 4, 2023

i updated the comment after WebAssembly/wasi-threads#16

Copy link
Collaborator

@abrown abrown left a comment

Choose a reason for hiding this comment

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

I think this is fine; I would want to link to the wasi-threads heading where this is discussed, but that's personal preference.

@abrown abrown merged commit 5a255d5 into WebAssembly:main Jan 6, 2023
john-sharratt pushed a commit to john-sharratt/wasix-libc that referenced this pull request Mar 6, 2023
This fixes TID-based locking used within libc.

Also, initialize detach_state.

cf. WebAssembly/wasi-threads#16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants