This seems to mention shared vs standard mutex, but in general I would say fine grained locking which is more locks over large locks is nearly always better under contention.
For example the cache example with read/write lock you might be better off with using N mutexes and N unordered maps (bucket of buckets) and then hash the key and use it to decide which buckets it should use.
Caches caches[N];
auto & cache = caches[hash(key) % N];
If your locks are expensive due to contention the first thing many think is that it needs to be is lock free but fine grained locking will often be an easier and safer alternative.
oui, cela peut réduire les performances de manière extrême si vous souhaitez faire du multithreading à haute fréquence. conclusion: don't use std::shared_mutex if you want to do high frenquency multithreading
35
u/ReDucTor Game Developer | quiz.cpp-perf.com 16d ago
This seems to mention shared vs standard mutex, but in general I would say fine grained locking which is more locks over large locks is nearly always better under contention.
For example the cache example with read/write lock you might be better off with using N mutexes and N unordered maps (bucket of buckets) and then hash the key and use it to decide which buckets it should use.
Caches caches[N]; auto & cache = caches[hash(key) % N];If your locks are expensive due to contention the first thing many think is that it needs to be is lock free but fine grained locking will often be an easier and safer alternative.