Skip to content

Commit

Permalink
Auto merge of rust-lang#110211 - joboet:queue_lock, r=Amanieu
Browse files Browse the repository at this point in the history
Replace pthread `RwLock` with custom implementation

This is one of the last items in rust-lang#93740. I'm doing `RwLock` first because it is more self-contained and has less tradeoffs to make. The motivation is explained in the documentation, but in short: the pthread rwlock is slow and buggy and `std` can do much better. I considered implementing a parking lot, as was discussed in the tracking issue, but settled for the queue-based version because writing self-balancing binary trees is not fun in Rust...

This is a rather complex change, so I have added quite a bit of documentation to help explain it. Please point out any part that could be explained better.

~~The read performance is really good, I'm getting 4x the throughput of the pthread version and about the same performance as usync/parking_lot on an Apple M1 Max in the usync benchmark suite, but the write performance still falls way behind what usync and parking_lot achieve. I tried using a separate queue lock like what usync uses, but that didn't help. I'll try to investigate further in the future, but I wanted to get some eyes on this first.~~ [Resolved](rust-lang#110211 (comment))

r? `@m-ou-se`
CC `@kprotty`
  • Loading branch information
bors committed Feb 12, 2024
2 parents aebf451 + 04282db commit b17491c
Show file tree
Hide file tree
Showing 5 changed files with 571 additions and 198 deletions.
2 changes: 2 additions & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,14 @@
#![feature(portable_simd)]
#![feature(prelude_2024)]
#![feature(ptr_as_uninit)]
#![feature(ptr_mask)]
#![feature(slice_internals)]
#![feature(slice_ptr_get)]
#![feature(slice_range)]
#![feature(std_internals)]
#![feature(str_internals)]
#![feature(strict_provenance)]
#![feature(strict_provenance_atomic_ptr)]
// tidy-alphabetical-end
//
// Library features (alloc):
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/pal/unix/locks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ cfg_if::cfg_if! {
pub(crate) use futex_condvar::Condvar;
} else {
mod pthread_mutex;
mod pthread_rwlock;
mod pthread_condvar;
mod queue_rwlock;
pub(crate) use pthread_mutex::Mutex;
pub(crate) use pthread_rwlock::RwLock;
pub(crate) use queue_rwlock::RwLock;
pub(crate) use pthread_condvar::Condvar;
}
}
195 changes: 0 additions & 195 deletions library/std/src/sys/pal/unix/locks/pthread_rwlock.rs

This file was deleted.

Loading

0 comments on commit b17491c

Please sign in to comment.