|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2004-08-07 13:41:27
Howard Hinnant wrote: ...
void read_write(rw_mutex& m, which_t w) {
sharable_lock<rw_mutex, true> read_lock(m);
// May need access to many releated which_t's
if (compute_expensive_result(w)) {
// Upgrade (blocks upcoming readers while pending)
scoped_lock<rw_mutex> write_lock(upgrade(read_lock));
if (read_lock.atomic_upgrade()) {
modify_state(w);
if (write_lock.upgrade_pending())
register_change(w);
}
else if (!computation_invalidated(w) || // check registry
compute_expensive_result(w)) {
modify_state(w);
write_lock.upgrade_pending() ?
register_change(w) : clear_registry();
}
else if (!write_lock.upgrade_pending()) {
clear_registry();
}
}
}
Oder (verbosity aside for a moment)?
regards,
alexander.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk