【问题标题】:boost::this_thread::disable_interruption usage confusionboost::this_thread::disable_interruption 使用混乱
【发布时间】:2010-05-06 11:19:45
【问题描述】:

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 我们也没有实现

它是如何工作的!???

【问题讨论】:

    标签: c++ linux boost multithreading


    【解决方案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;
            }
        }
    

    析构函数和方法也都有。

    【讨论】:

      【解决方案2】:

      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

      您根据您的平台链接到适当的链接

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-19
        • 1970-01-01
        • 1970-01-01
        • 2012-01-19
        • 1970-01-01
        • 2020-10-07
        • 2013-06-13
        • 1970-01-01
        相关资源
        最近更新 更多