Boost logo

Boost :

From: Hillel Y. Sims (hsims_at_[hidden])
Date: 2002-09-30 11:25:44

"David Abrahams" <dave_at_[hidden]> wrote in message
> OK. Sounds like the sort of thing that could be implemented at the library
> level, if only everyone would cooperate and use the facilities. Maybe we
> need a Boost error-handling library. Sounds like with all these
> nasty-C++-implementation-choices and thread cancellation safety issues, we
> probably do.

I think this is a great idea. May I suggest some possible entrants:

- ScopeGuard

- CancelGuard - disable thread-cancellation in critical regions
(platform-specific implementation: no effect on non-pthread platforms)

- NoThrowGuard - similar protection as "throw()" spec, but can be applied at
any block scope without need for interface-polluting ES, also provides
cancellation protection via CancelGuard. ( )

class CancelGuard : boost::noncopyable
    // pthread impl:
      { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &m_origState); }
      { pthread_setcancelstate(m_origState, 0); }

    int m_origState;

class NoThrowGuard : boost::noncopyable
    NoThrowGuard() : m_wasHandling(std::uncaught_exception())
         if (std::uncaught_exception() && !m_wasHandling)
            std::unexpected(); // (or maybe terminate()?)

    CancelGuard m_cg;
    const bool m_wasHandling;

(I actually usually use CANCEL_GUARD and NOTHROW_REGION macros for
shortcuts, since they don't really need to be named objects.)



Hillel Y. Sims
FactSet Research Systems
hsims AT

Boost list run by bdawes at, gregod at, cpdaniel at, john at