oneTBB icon indicating copy to clipboard operation
oneTBB copied to clipboard

task_dispatcher.h calls 'do_throw_noexcept' without any TBB_USE_EXCEPTIONS guard

Open GertyP opened this issue 2 years ago • 2 comments

In 'task_dispatcher.h', local_wait_for_all, there's a call to do_throw_noexcept(...) - https://github.com/oneapi-src/oneTBB/blob/11545bd606be3187ffb3d7507c9ab21705123e61/src/tbb/task_dispatcher.h#L359

However, if the build has been configured with TBB_USE_EXCEPTIONS undefined (or defined to 0) then, in 'src/tbb/exception.cpp', the only implementations for do_throw_noexcept are entirely excluded from compling, resulting in a link error, referencing the undefined do_throw_noexcept symbol from within 'task_dispatcher.h'.

Since a throw from a noexcept function will result in a std::terminate() then, if TBB_USE_EXCEPTIONS is enabled, the code essentially becomes -

if (global_control::active_value(global_control::terminate_on_exception) == 1) {
    std::terminate();  // do_throw_noexcept([] { throw; });
}

But what would we want when TBB_USE_EXCEPTIONS is disabled? In both cases, it seems reasonable to simply directly call std::terminate() there; do_throw_noexcept([] { throw; }); seems just a slightly elaborate, round-about way of calling terminate. Is there a benefit to throwing from a noexcept func, over calling std::terminate()?

GertyP avatar Sep 18 '23 16:09 GertyP

This is just clarifying that this isn't only a question about the weird use of do_throw_noexcept(... throw ...) but primarily pointing out a bug with the build when it's configured with TBB_USE_EXCEPTIONS disabled; it fails to build.

I was suggesting this problem be avoided by replacing the problem line with std::terminate() (although perhaps it'd be slightly nicer to make use of PRINT_ERROR_AND_ABORT(exc_name, msg) in this case [but that macro would then need moving out of the TBB_USE_EXCEPTIONS-guarded block] ) and, as a secondary concern, I was interested in learning the rationale behind the strange looking existing line of code.

GertyP avatar Sep 20 '23 12:09 GertyP

I think this is related to #864

isaevil avatar Sep 25 '23 08:09 isaevil