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

Don't define _POSIX_THREADS unless threads are enabled. #356

Merged
merged 2 commits into from
Dec 7, 2022

Conversation

sunfishcode
Copy link
Member

Fixes #355.

@abrown abrown merged commit 7250bd4 into main Dec 7, 2022
@abrown abrown deleted the sunfishcode/pthread-macro branch December 7, 2022 21:55
@anuraaga
Copy link

anuraaga commented Dec 7, 2022

Is it possible to move all the thread related code into the if block? I think most of these (including timers) are not supported, probably just the clock related ones are. Sorry my issue wasn't clear on that.

For context, the library I found uses _POSIX_READER_WRITER_LOCKS presumably because it doesn't create threads, only uses mutex.

@sbc100
Copy link
Member

sbc100 commented Dec 8, 2022

Also, while looking into it I discovered that a more common say to signal no support is to define these macros to -1. Not defining them at seems like it is acceptable but maybe less explicit. For example here is hurd declaring that it doesn't support stuff: https://codebrowser.dev/glibc/glibc/sysdeps/mach/hurd/bits/posix_opt.h.html#163

The found some documentation in https://pubs.opengroup.org/onlinepubs/000095399/ under unistd.h.

john-sharratt pushed a commit to john-sharratt/wasix-libc that referenced this pull request Mar 6, 2023
…y#356)

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

Fixes WebAssembly#355.

* Remove `_POSIX_THREADS` from predefined-macros.txt.
@kateinoigakukun
Copy link
Contributor

kateinoigakukun commented May 4, 2024

While porting libidn, I hit a similar issue that gnulib's getopt.c determines the availability of flockfile based on existence of _POSIX_THREAD_SAFE_FUNCTIONS definition. Since wasi-libc defines it, it tries to use flockfile even though it's unavailable in wasip1 (without -threads). https://github.com/coreutils/gnulib/blob/b86d31ade5e8284df1efe339890b674eedf89bcd/lib/getopt.c#L48

I guessed defining these macros to -1 might be a common way in the definition aspect, but checking the definition existence seems more common in use sites. So I code searched both use styles defined(_POSIX_THREADS) and _POSIX_THREADS == in GitHub, and the former seems more common way.

Of course, checking both 1. the definition existence, 2. it's not -1 is the most correct way. But given that most of use-sites use defined style check, and the unistd.h doc allows not defining it to advertise that the feature is unsupported, what do you think about moving those threads consts under if block too not to define them? @sbc100

@sbc100
Copy link
Member

sbc100 commented May 4, 2024

what do you think about moving those threads consts under if block too not to define them?

Sorry, which threads consts are you referring to here?

Do you mean moving all the other _POSIX_THREAD_XX macros? If so, then yes that does seem reasonable.

@kateinoigakukun
Copy link
Contributor

@sbc100 Ah, yes. I mean all other _POSIX_THREAD_XXX macros. Then I'll create a PR

kateinoigakukun added a commit to kateinoigakukun/wasi-libc that referenced this pull request May 4, 2024

Verified

This commit was signed with the committer’s verified signature.
abrown Andrew Brown
This is a follow-up to WebAssembly#356
kateinoigakukun added a commit to kateinoigakukun/wasi-libc that referenced this pull request May 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
This is a follow-up to WebAssembly#356
kateinoigakukun added a commit to kateinoigakukun/wasi-libc that referenced this pull request May 4, 2024
This is a follow-up to WebAssembly#356
abrown pushed a commit that referenced this pull request May 6, 2024
This is a follow-up to #356
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.

unistd.h declares threads support even when not enabled
5 participants