boost :: this_thread :: disable_interruption使用混乱

时间:2010-05-06 11:19:45

标签: c++ linux boost multithreading

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的实现,只包含原型。

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

它是如何工作的!???

2 个答案:

答案 0 :(得分:1)

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;
        }
    }

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

答案 1 :(得分:0)

disable_interruption有2个实现。

  1. boost_1_42_0/libs/thread/src/pthread/thread.cpp
  2. boost_1_42_0/libs/thread/src/win32/thread.cpp
  3. 根据您的平台链接相应的