[c++-pthreads] Re: thread-safety definition
Alexander Terekhov
boo at terekhov.de
Fri Jan 9 14:42:35 UTC 2004
Wil Evers wrote:
[...]
> If catching (and not rethrowing) this second exception breaks the
> cancellation machinery, then it is the cancellation machinery - and not
> the program in question - that is broken. In other words: we need a way
> to prevent this scenario.
Here's a sort of "current way" to prevent this scenario:
http://www.terekhov.de/DESIGN-futex-CV.cpp
class cancel_off_guard {
//*** unimplemented since it's non-copyable/non-copy-constructible
cancel_off_guard(const cancel_off_guard &);
cancel_off_guard & operator=(const cancel_off_guard &);
int m_old_cancel_state;
public:
cancel_off_guard() {
int status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,
&m_old_cancel_state);
assert(!status);
}
~cancel_off_guard() {
int status = pthread_setcancelstate(m_old_cancel_state,
&m_old_cancel_state);
assert(!status);
}
}; //*** class cancel_off_guard
~futex_condvar() {
mutex::guard guard(m_mutex);
assert(m_waiters[0] == m_wakeups);
while (m_waiters[0]) {
int ftx = m_futex = EOC();
mutex::release_guard release_guard(guard);
cancel_off_guard no_cancel;
m_futex.wait(ftx);
}
}
However, the standard mandated mandatory 2-phase EH (with fixed
exception specs/implicit throw() ES for dtors) and "intelligent"
cancellation points (and async-cancel-regions, of course) is the
way to go, I believe strongly.
regards,
alexander.
More information about the c++-pthreads
mailing list