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

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


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:



class Foo {


    std::vector& m_vec;


    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;


    Foo f(vec);
    // Constructs graph and nodes

    tbb::flow::graph g;

    tbb::flow::broadcast_node start(g);

    tbb::flow::continue_node fooNode(g, f); 
    // Constructs edge

    tbb::flow::make_edge(start, fooNode);
    // Executes graph

    std::cout << "Executing" << std::endl;

    try {




    catch(std::out_of_range& ex) {

        std::cout << "Exception: " << ex.what() << std::endl;

    std::cout << "Finished" << std::endl;

    return 0;

The above code will hang upon returning 0. Is this expected behaviour? Do I have to cancel all tasks in the graph manually somehow?



3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Andrew,

thanks for reporting the problem. It certainly looks like a bug; we will investigate it.

Cool, thanks! Also the above only works on Windows - on Linux, an exception of type tbb::captured_exception is thrown.

Leave a Comment

Please sign in to add a comment. Not a member? Join today