This is drawing broad conclusions from a specific RW mutex implementation. Other implementations adopt techniques to make the readers scale linearly in the read-mostly case by using per-core state (the drawback is that write locks need to scan it). One example is folly::SharedMutex, which is very battle-tested: https://uvdn7.github.io/shared-mutex/ There are more sophisticated techniques such as RCU or hazard pointer…
Read Locks Are Not Your Friends
11–20 of 24 posts
Re: Read Locks Are Not Your Friends
#12This is drawing broad conclusions from a specific RW mutex implementation. Other implementations adopt techniques to make the readers scale linearly in the read-mostly case by using per-core state (the drawback is that write locks need to scan it). One example is folly::SharedMutex, which is very battle-tested: https://uvdn7.github.io/shared-mutex/ There are more sophisticated techniques such as RCU or hazard pointer…
Re: Read Locks Are Not Your Friends
#13I'd be super interested in how this compares between cpu architectures, is there an optimization in Apple silicon that makes this bad while it'd fly on Intel/AMD cpus?
Re: Read Locks Are Not Your Friends
#14Re: Read Locks Are Not Your Friends
#15I'd be super interested in how this compares between cpu architectures, is there an optimization in Apple silicon that makes this bad while it'd fly on Intel/AMD cpus?
I've observed the same behavior on AMD and Intel at $WORK. Our solution (ideal for us, reads happening roughly 1B times more often than writes) was to pessimize writes in favour of reads and add some per-thread state to prevent cache line sharing. We also tossed in an A/B system, so reads aren't delayed even while writes are happening; they just get stale data (also fine for our purposes).
It's essentially just an atomic pointer that can be swapped out.
Re: Read Locks Are Not Your Friends
#16This is drawing broad conclusions from a specific RW mutex implementation. Other implementations adopt techniques to make the readers scale linearly in the read-mostly case by using per-core state (the drawback is that write locks need to scan it). One example is folly::SharedMutex, which is very battle-tested: https://uvdn7.github.io/shared-mutex/ There are more sophisticated techniques such as RCU or hazard pointer…
Re: Read Locks Are Not Your Friends
#17Does this apply also to std::shared_mutex in C++? This is a timely article if so; I’m in the middle of doing some C++ multithreading that relies on a shared_mutex. I have some measuring to do.
Re: Read Locks Are Not Your Friends
#18Re: Read Locks Are Not Your Friends
#19Does this apply also to std::shared_mutex in C++? This is a timely article if so; I’m in the middle of doing some C++ multithreading that relies on a shared_mutex. I have some measuring to do.
mostly yes.
Re: Read Locks Are Not Your Friends
#20Also Fedor Pikus has some nice cppcon talks from years ago on all this. Very low level.