Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2415 Discussions

Exception in flow graph results in graph.wait_for_all() hanging - bug?

ahelwer
New Contributor I
188 Views
Hello,

I've found that when an exception is thrown during execution of a flow graph node task, the exception propagates upward to the main thread as expected but cancellation of tasks does not seem to take place as described in Section 5.2 (page 39) of the tutorial. The result is that subsequent calls to graph.wait_for_all() hang. Notably, since wait_for_all() is called during the graph object's destructor, an exception which should kill the process instead causes it to hang as the graph object goes out of scope and its destructor is called. Here is some simple example code demonstrating the problem:

[cpp]#include #include #include class Foo { private: std::vector& m_vec; public: Foo(std::vector& vec) : m_vec(vec) { } void operator() (tbb::flow::continue_msg) const { m_vec.at(m_vec.size()); // Will throw out_of_range exception } }; int main() { // Initializes body std::vector vec; vec.push_back(0); Foo f(vec); // Constructs graph and nodes tbb::flow::graph g; tbb::flow::broadcast_node<:FLOW::CONTINUE_MSG> start(g); tbb::flow::continue_node<:FLOW::CONTINUE_MSG> fooNode(g, f); // Constructs edge tbb::flow::make_edge(start, fooNode); // Executes graph std::cout << "Executing" << std::endl; try { start.try_put(tbb::flow::continue_msg()); g.wait_for_all(); } catch(std::out_of_range& ex) { std::cout << "Exception: " << ex.what() << std::endl; } std::cout << "Finished" << std::endl; return 0; }[/cpp] The above code will hang upon returning 0. Is this expected behaviour? Do I have to cancel all tasks in the graph manually somehow?

Thanks,

Andrew
0 Kudos
2 Replies
Alexey_K_Intel3
Employee
188 Views
Hi Andrew,

thanks for reporting the problem. It certainly looks like a bug; we will investigate it.
ahelwer
New Contributor I
188 Views
Cool, thanks! Also the above only works on Windows - on Linux, an exception of type tbb::captured_exception is thrown.
Reply