c++ - 在 boost 中禁用中断会禁用上下文切换吗?

标签 c++ multithreading boost

据我了解,操作系统内核负责生成硬件计时器中断,调度程序使用这些中断来为每个内核分配每个线程的时间片,并根据需要执行上下文切换。我的印象是这只能从内核空间完成,并且禁用它通常是不受欢迎的。然而,boost 文档似乎声明它允许禁用中断:

https://www.justsoftwaresolutions.co.uk/threading/thread-interruption-in-boost-thread-library.html

使用 boost 禁用中断会有效地暂停调度程序和上下文切换吗?或者,boost使用“中断”仅意味着用户空间信号或异常或唤醒线程的东西?

遗憾的是,“中断”这个术语似乎有点过多,这很容易使事情变得困惑。

有人可以解释一下 boost 在这里的中断系统实际上做了什么,以及它与上下文切换有何关系?

最佳答案

Will disabling interrupts with boost effectively pause the scheduler and context switching?

没有。

Or, is boost using 'interrupt' to mean only user-space signals or exceptions or something to wake up threads?

是的。它只影响线程中断 - 这是一个可选的 Boost Thread 功能,仅在使用 boost::threadinterruption points from Boost Thread 时可用。 :

Predefined Interruption Points

The following functions are interruption points, which will throw boost::thread_interrupted if interruption is enabled for the current thread, and interruption is requested for the current thread:

  • boost::thread::join()
  • boost::thread::timed_join()
  • boost::thread::try_join_for(),
  • boost::thread::try_join_until(),
  • boost::condition_variable::wait()
  • boost::condition_variable::timed_wait()
  • boost::condition_variable::wait_for()
  • boost::condition_variable::wait_until()
  • boost::condition_variable_any::wait()
  • boost::condition_variable_any::timed_wait()
  • boost::condition_variable_any::wait_for()
  • boost::condition_variable_any::wait_until()
  • boost::thread::sleep()
  • boost::this_thread::sleep_for()
  • boost::this_thread::sleep_until()
  • boost::this_thread::interruption_point()

事实上,它使用异常实现了一种协作中断风格(boost::thread_interruption)。

关于c++ - 在 boost 中禁用中断会禁用上下文切换吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74746692/

相关文章:

带有 boost scoped_ptr 的 C++ 多态性

java - 在桌面和移动 CPU 上使用 Java 进行并行处理

java - 等待直到阻塞队列已满

java - 如何在多线程环境中使构建器模式线程安全?

multithreading - 我应该使用哪种 boost 多线程设计模式?

c++ - 线程安全设置

c++ - 找不到过程入口点 __gxx_personality_v0

c++ - 指向 std::invoke 中成员函数对象的指针

C++:二维数组,如何找到列中差异最大的行?

c++ - '.push_back' 的左边必须有类/结构/union