boost / thread / pthread / shared_mutex.hpp包含以下代码:

...
#include <boost/thread/detail/thread_interruption.hpp>
...

class shared_mutex
{
    ...
    void lock_shared()
    {
        boost::this_thread::disable_interruption do_not_disturb;
        boost::mutex::scoped_lock lk(state_change);

        while(state.exclusive || state.exclusive_waiting_blocked)
        {
            shared_cond.wait(lk);
        }
        ++state.shared_count;
    }
    ...
};

但是boost / thread / detail / thread_interruption.hpp不包含disable_interruption的实现,仅包含原型(prototype)。

在boost_1_42_0 / libs / thread / src / pthread中,我们也没有实现

它是如何工作的!???

最佳答案

grepboost_1_42_0/libs/thread/src/pthread/thread.cpp中找到它:

    disable_interruption::disable_interruption():
        interruption_was_enabled(interruption_enabled())
    {
        if(interruption_was_enabled)
        {
            detail::get_current_thread_data()->interrupt_enabled=false;
        }
    }

析构函数和方法也都存在。

10-08 08:39
查看更多