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

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

imagem de ahelwer

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:

#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 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 {

        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;

}
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

3 posts / 0 new
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
imagem de Alexey Kukanov (Intel)

Hi Andrew,

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

imagem de ahelwer

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

Faça login para deixar um comentário.