boostorg / thread

Boost.org thread module
http://boost.org/libs/thread
203 stars 162 forks source link

basic_condition_variable::relocker::~relocker can throw an exception #121

Closed kalman5 closed 7 years ago

kalman5 commented 7 years ago

relocker DTOR is implemented as the following:

            ~relocker()
            {
                if(unlocked)
                {
                    lock.lock();
                }

            }

that lock.lock() can throw (see unique_lock::lock in lock_types.hpp) leading to std::terminate if compiled in c++11 mode

viboes commented 7 years ago

I will try to do the lock outside a destructor and propagate the exception.

Please could you tell me when do you see the call to terminate?

viboes commented 7 years ago

The problem I have are the exception warranties. What will be the state when there is a failure when trying to lock? The resource will be unusable. What the user should do when receiving an exception?

There are other uses similar to the relocker elsewhere in the library.

kalman5 commented 7 years ago

You need to mark those DTOR as noexcept(false); if they can throw. Basically even while not being inside a stack unwinding that will make the software terminating.

viboes commented 7 years ago

Ok, I see.

viboes commented 7 years ago

Done in boost 1.65.