|
Boost : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-07-05 21:55:52
On Jul 5, 2004, at 10:35 PM, Howard Hinnant wrote:
> vs this:
>
> void do_sale(rw_mutex& m)
> {
> read_lock rl(m);
>
> long balance = get_balance();
> long cost = get_total_cost();
>
> if (balance > cost)
> {
> rl.unlock(m);
> write_lock wl(m);
> set_balance(balance - cost);
> wl.transfer_to_read_lock(rl);
> balance = get_balance();
> }
> // ...
> }
Oops, that should be:
vs this:
void do_sale(rw_mutex& m)
{
read_lock rl(m);
long balance = get_balance();
long cost = get_total_cost();
if (balance > cost)
{
rl.unlock(m);
write_lock wl(m);
cost = get_total_cost();
set_balance(get_balance() - cost);
wl.transfer_to_read_lock(rl);
balance = get_balance();
}
// ...
}
but still looks much simpler, and smaller code size to me.
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk