据我了解,操作系统内核负责生成硬件计时器中断,调度程序使用这些中断来为每个内核分配每个线程的时间片,并根据需要执行上下文切换。我的印象是这只能从内核空间完成,并且禁用它通常是不受欢迎的。然而,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::thread
和 interruption 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/