4 ms·
> Shared ref or exclusive mut There's std::shared_mutex, which allows multiple readers and a writer.
by adhesive_wombat 3y ago
> Shared ref or exclusive mut
There's std::shared_mutex, which allows multiple readers and a writer.
- tialaramex 3y agoThat's exactly the scenario your parent is describing. You can have (multiple) readers or a single writer. You cannot have both. The analogous Rust type is std::sync::RwLock<T> (but as with Mutex, RwLock is a wrapper, so it is actually protecting something inside it, not just providing the raw mutex type). If you've been using std::shared_mutex assuming you can have both then, I guess it's good luck that you didn't cause a deadlock of some sort, but at least this API unlike most C++ APIs isn't just "LOL, if you use this wrong it's Undefined Behaviour, all bets are off, goodbye" in the respect that matters to you.
- adhesive_wombat 3y agoOh I see, sorry I misunderstood that. Yes indeed the readers won't be able read while the writer is writing.