|
Boost : |
Subject: [boost] [thread] Exception based timed locks
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-01-19 19:03:28
Hi,
I've read recently about timed locks throwing an exception when there is a timeout.
What do you think about this behaviour?
Could the thread library provide both?
Next follows a piece of code without exceptions
while (polling) {
t=now()+100;
boost::unique_lock<boost::mutex> l1(m1, t);
if (l1.has_lock() {
boost::unique_lock<boost::mutex> l2(m2, t);
if (l2.has_lock() {
boost::unique_lock<boost::mutex> l3(m3, t);
if (l2.has_lock() {
foo();
polling = false;
} else execute_on_failed();
} else execute_on_failed();
} else execute_on_failed();
}
and now with exceptions
while (polling)
try {
t=now()+100;
boost::exception_unique_lock<boost::mutex> l1(m1, t);
boost::exception_unique_lock<boost::mutex> l2(m2, t);
boost::exception_unique_lock<boost::mutex> l3(m3, t);
foo();
polling = false;
} catch (timeout_exception& ex) {execute_on_failed(); }
What do you think about a try_lock_until, try_lock_for functions
while (polling)
try {
boost::try_lock_for(100, m1, m2, m3);
foo();
polling = false;
} catch (timeout_exception& ex) {execute_on_failed(); }
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk