Home > database >  Does disabling interrupts in boost disable context switching?
Does disabling interrupts in boost disable context switching?

Time:12-13

It is my understanding that the OS kernel is responsible for generating hardware timer interrupts that are used by the scheduler to hand out each thread's timeslice for each core and perform context switching as needed. I was under the impression that this could only be done from kernel space, and disabling it is usually frowned upon. However, boost documentation seems to state that it allows the disabling of interrupts:

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

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?

Sadly, the term 'interrupt' seems to be rather overloaded, and this makes it easy to get things confused.

Can someone explain what boost is actually doing with its interrupt system here, and how it relates to context switches?

CodePudding user response:

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

No.

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

Yes. It only affects thread interruption - which is an optional Boost Thread feature, which is only available when using boost::thread and 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()

Indeed it implements a style of cooperative interruption using exceptions (boost::thread_interruption).

  • Related