
Bruno MartÃnez Aguerre <br1 <at> internet.com.uy> writes:
What about a latent_write_lock?
It's semantics would be to block on contruction until it only shares the mutex with read_locks. A write_lock could be contructed from a latent_write_lock and this would always work, because another latent_write_lock would still be blocked in it's constructor. This kind of lock would be useful for situations in which you have to read a structure to know if you have to write on it.
Bruno Martinez
Interesting, this divides read locks into promotable and non-promotable variants? If you have a design where a lot of threads take concurrent read locks, and the case of promotion is rare, then having them all use latent_write_locks will unnecessarily serialise them. Allowing promotion failure instead would only affect rare cases of promotion contention. If you have a case where promotion is common, then you probably won't gain much over simply using write locks, will you? If you can mix a number of read-only locks with a small number of latent_write_locks for which promotion is uncommon, then you have an optimum result. Matt