In commit “doc: Add comment to cs_main and mempool::cs” (fa64bb42e97b6c6c58e83badca88d386f99dbcd2)
I think making a comparison to read/write locks makes this more confusing than it needs to be. Read locks normally are shared, not exclusive. And the requirement to lock cs_main
for write access seems too broad, and doesn’t give a justification.
I would suggest a comment that just says when you need to lock the mutexes and why:
0/**
1 * This mutex needs to be locked when accessing mapTx.
2 *
3 * [@par](/bitcoin-bitcoin/contributor/par/) Relationship to cs_main
4 * Locking both mempool.cs and cs_main gives a view of the mempool which is
5 * compatible with the current chain tip. To guarantee this, both mutexes need
6 * to be locked when adding transactions to the mempool or changing the
7 * chain tip. But locking mempool.cs by itself is sufficient for reading
8 * transactions from the mempool, or removing transactions from it.
9 */