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

unistd.h declares threads support even when not enabled #355

Closed
anuraaga opened this issue Dec 7, 2022 · 2 comments · Fixed by #356
Closed

unistd.h declares threads support even when not enabled #355

anuraaga opened this issue Dec 7, 2022 · 2 comments · Fixed by #356

Comments

@anuraaga
Copy link

anuraaga commented Dec 7, 2022

I noticed that unistd.h seems to declare support for threads on all wasi-libc builds

https://github.com/WebAssembly/wasi-libc/blob/main/libc-top-half/musl/include/unistd.h#L339

This is despite pthread.h not being available. As far as I can tell, it's not possible to compile a library that has branches based on whether threads are available or not, for example to use a real or no-op mutex.

It seems like guarding on __wasilibc_unmodified_upstream would reflect the current state of wasi-libc. But I know there is the ongoing THREAD_MODEL=posix work as well. It's not obvious to me how to tweak this include file to reflect the default state of wasi-libc while also set the flags when in pthread mode.

Is it possible to fix this so the variables aren't set in the default build?

@sunfishcode
Copy link
Member

One option here would be to use ifdef _REENTRANT to do this. I wonder if we'll ever want a mode where threads are supported and _REENTRANT is not defined.

Another option would be to move forward with the new target triple idea that's been tossed around. wasm32-wasi-pthread or so, and then we could get a predefined target macro like __wasi_pthread__ or so.

@sbc100
Copy link
Member

sbc100 commented Dec 7, 2022

Use _REENTRANT (at least for now) seems pretty reasonable to me. Clang currently defines _REENTRANT whenever posix threads is enabled, so it seems like pretty precise correlation (at least today):

https://github.com/llvm/llvm-project/blob/6697140ba1d5ab03ad8102b139f5c543f1d8e616/clang/lib/Basic/Targets/OSTargets.cpp#L47-L48

sbc100 added a commit to emscripten-core/emscripten that referenced this issue Dec 7, 2022
abrown pushed a commit that referenced this issue Dec 7, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* Don't define `_POSIX_THREADS` unless threads are enabled.

Fixes #355.

* Remove `_POSIX_THREADS` from predefined-macros.txt.
sbc100 added a commit to emscripten-core/emscripten that referenced this issue Dec 8, 2022
sbc100 added a commit to emscripten-core/emscripten that referenced this issue Dec 8, 2022
sbc100 added a commit to emscripten-core/emscripten that referenced this issue Dec 9, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
john-sharratt pushed a commit to john-sharratt/wasix-libc that referenced this issue Mar 6, 2023
…y#356)

* Don't define `_POSIX_THREADS` unless threads are enabled.

Fixes WebAssembly#355.

* Remove `_POSIX_THREADS` from predefined-macros.txt.
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 a pull request may close this issue.

3 participants