
30 Jun
2004
30 Jun
'04
12:10 p.m.
Michael Glassford wrote:
Finally, to take two more realistic use cases:
void f(read_write_mutex m) { read_write_mutex::write_lock w(m);
//...
read_write_mutex::read_lock r(w); //lock promotion
//... }
And:
void f(read_write_mutex m) { read_write_mutex::write_lock r(m);
//...
read_write_mutex::read_lock w(r); //lock demotion
//... }
The second lock does unnecessary work in demoting/promoting the lock for the first lock, which then immediately unlocks it.
This is a very good point, since in the second example the unnecessary promotion would block. This seems to suggest that read_write_lock is necessary in such a scenario.