3 ms·
> If you’re using this kind of thing ... why wouldn’t you just use a mutex or reader writer mutex. >> you want the readers to be able to read multiple values a
by mrkeen 3y ago
> If you’re using this kind of thing ... why wouldn’t you just use a mutex or reader writer mutex.
>> you want the readers to be able to read multiple values atomically.
I read this in TFA, and interpreted it to mean you could read multiple values atomically, which would be an answer to your question - mutexes only protect one thing and you can't combine them atomically.
But looking at the code, it seems that this does no better? It only allows reading of multiple values insofar as it protects one hard-coded struct which happens to have multiple fields.
- slashdev 3y agoYou can’t do that without a mutex. This provides a way to read a consistent snapshot of multiple atomic values without a mutex. Obviously you could just use a mutex. This may perform better under some workloads, especially if writes are very rare.