gpt4 book ai didi

c++ - boost::this_thread::disable_interruption 使用困惑

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:12:29 26 4
gpt4 key购买 nike

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

析构函数和方法也都在那里。

关于c++ - boost::this_thread::disable_interruption 使用困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2780631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com