Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-10-08 11:58:06


Peter Dimov wrote:
[...]
> Right. You want to autodetect whether to operate in a throw mode or a
> nothrow mode. This will never work. :-)

Stop advocating blind use of catch(...), Peter!

>
> The problem is that you can't count on people marking nothrow regions
> throw() if you can't count on them using operation() correctly (i.e.
> disabling cancelation in nothrow regions.)

Not quite. It's kinda "performance optimization". The idea is that
all cancelation points (std::test_thread_cancel() including) shall
NOT throw *unexpected* cancel exceptions... even if cancelation is
enabled -- there should be no need to just waste cycles on disable/
restore of thread cancelation state (quite expensive atomic stuff).
Well, I should have written

void operation() {
  bool do_test_thread_cancel = true;
  /**/
  SOME_LOOP {
    /**/
    if (do_test_thread_cancel && std::thread_cancel_pending()) {
      if (std::thread_cancel_enabled() &&
          std::expected_exception<std::thread_cancel_request>()) {
        /**/
        throw std::thread_cancel_request();
      }
      do_test_thread_cancel = false;
    }
    /**/
  }
  /**/
}

right from the beginning, I guess. Arguably, we can do "almost the
same" without exposing std::expected_exception() (and, also on the
plus side, without any "double lookup"... it can be optimized away,
but):

void operation() {
  bool do_test_thread_cancel = true;
  /**/
  SOME_LOOP {
    /**/
    if (do_test_thread_cancel && std::thread_cancel_pending()) {
      std::test_thread_cancel();
      do_test_thread_cancel = false;
    }
    /**/
  }
  /**/
}

regards,
alexander.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk