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

option to avoid pthread_rwlock_t on macos #14468

Open
billzez opened this issue Jan 26, 2023 · 4 comments
Open

option to avoid pthread_rwlock_t on macos #14468

billzez opened this issue Jan 26, 2023 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior os-macos standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@billzez
Copy link
Contributor

billzez commented Jan 26, 2023

pthread_rwlock_t is supposed to be read reentrant, but on macos it deadlocks. Zig's DefaultRwLock is read reentrant. It would be nice have a std_option to avoid pthread_rwlock_t.

@nektro
Copy link
Contributor

nektro commented Jan 26, 2023

cc @kprotty for triage

@billzez
Copy link
Contributor Author

billzez commented Jan 26, 2023

It looks like posix does not guarantee read reentrancy, so the mac deadlock is fine because its considered undefined behavior. That said the semantics between DefaultRwLock and pthread_rwlock_t are different, so pthread_rwlock_t should probably be dropped altogether.

@kprotty
Copy link
Member

kprotty commented Jan 26, 2023

IMO, RwLocks in general should be dropped (there's often better ways to implement read-heavy workloads with occasional writers than using RwLocks). For a quick fix though, a Futex based RwLock thats read-reentrant can be implemented using futex (see either the writer-preferred alg or the linked reader-preferred alg from this PR).

@billzez
Copy link
Contributor Author

billzez commented Jan 26, 2023

For now I can use std.Thread.RwLock.DefaultRwLock directly. Not ideal, as it uses two mutexes and a condition variable, but it works on all platforms. My only point here is that IMHO PosixRwLock should probably be removed since it has broken semantics.

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library. os-macos labels Apr 10, 2023
@andrewrk andrewrk added this to the 0.11.0 milestone Apr 10, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants