Currently many mutexes are recursive to accommodate for callers that have the mutex already locked. However, people seem not to like recursive mutexes, see also #19303.
Moreover, there are many logic races in the codebase. (Not data races, which are UB, but code that returns valid, but logically inconsistent data. For example #25077).
For example, if a method wants to return the latest block hash and the height of that block, it could do:
0return { chain.tip_hash(), chain.tip_height() };
Assuming that chain
has a private lock, which is acquired in its member methods. Though, in a multi-threaded context this may return a stale hash, which does not correspond to the height. So it would be nice to have a way to fix that, even if all locks are private and non-recursive.
So I was thinking about a helper that returns a locked chain to the caller:
0auto lc{chain.locked()};
1return { lc.tip_hash(), lc.tip_height() };
Does this sound like a good idea?