Skip to content

Use libpthread primitives for OpenBSD mutexes. #82392

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

3405691582
Copy link
Member

There has been some discussion as to whether this is the right approach, centered around internal pointers in the underlying mutex structure. After much thought, let's commit this for now. The argument:

  • While it is true that OpenBSD has futex(2) and in fact is used in the underlying implementations in Dispatch. I'm not confident right now creating robust locking primitives by hand from futexes. It would be ideal to just delegate all of this to Dispatch, but Dispatch doesn't expose a ready-use API for mutexes. Cobbling one together might be possible, but that would take some time and finesse.

  • While recent versions of C and C++ have language support for mutexes, they are implemented in many cases by libpthread anyway, so there is nothing inherently gained right now by not using the pthread API other than portability.

  • While the concern for internal pointers for the pthread API is important, the OpenBSD is mitigated by the fact that pthread_mutex_t is pointer-valued on the platform. The concern that this might not always be the case is mitigated by the fact that this commit does not attempt to use the pthread implementation as a catch-all for all platforms.

  • The alternative is to use MutexUnavailable, but given Foundation has some dependencies on Mutex, this may cause problems elsewhere throughout the port.

@3405691582 3405691582 requested a review from a team as a code owner June 21, 2025 14:23
There has been some discussion as to whether this is the right approach,
centered around internal pointers in the underlying mutex structure.
After much thought, let's commit this for now. The argument:

* While it is true that OpenBSD has futex(2) and in fact is used in
  the underlying implementations in Dispatch. I'm not confident right now
  creating robust locking primitives by hand from futexes.
  It would be ideal to just delegate all of this to Dispatch, but
  Dispatch doesn't expose a ready-use API for mutexes. Cobbling one
  together might be possible, but that would take some time and finesse.

* While recent versions of C and C++ have language support for mutexes,
  they are implemented in many cases by libpthread anyway, so there
  is nothing inherently gained right now by not using the pthread API
  other than portability.

* While the concern for internal pointers for the pthread API is
  important, the OpenBSD is mitigated by the fact that pthread_mutex_t is
  pointer-valued on the platform. The concern that this might not always
  be the case is mitigated by the fact that this commit does not attempt
  to use the pthread implementation as a catch-all for all platforms.

* The alternative is to use MutexUnavailable, but given Foundation has
  some dependencies on Mutex, this may cause problems elsewhere
  throughout the port.
@3405691582 3405691582 force-pushed the openbsd_mutex_pthread branch from 65609b2 to 3bb369c Compare June 21, 2025 14:26
@3405691582
Copy link
Member Author

@swift-ci please test.

1 similar comment
@3405691582
Copy link
Member Author

@swift-ci please test.

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.

1 participant