Tuesday, 15 July 2014

c++ - Why use boost disable_interruption when you want to test for interruption_requested()? -


In many places, I see the code like this:

  zero thread function () {Boost :: disable this_thread :: disable_interruption; While (! Boost :: this_thread :: interruption_requested ()) {// do stuff}}  

It seems to me that I "disable" the thread function interrupted, but Then I'll test for an interruption, miraculously, it works, can someone tell me what is it really behind the scenes? Thanks!

disabled-transfer actually prevents thread from interrupting; This does not prevent the disrupted status from being set. Then interruption_requested tests whether the interrupted status is is fixed.

See Boost Document: Specifically

Various methods are classified

  • Prevention of blockage prevents blockage: stops blockage
  • If there is an indication, the interruption still marks the thread as a 'constrained request'
  • interruption_requested method checks whether an interrupt request

No comments:

Post a Comment