TBB flow graph调试模式下死锁问题排查求助
TBB flow_graph调试模式死锁问题分析
仅在C++20 64位VS调试模式下出现死锁,死锁发生在include\oneapi\tbb\flow_graph.h的remove_node函数调用时。请求分析以下代码是自身存在bug还是TBB的bug:
代表性示例代码
#include <unordered_map> #include <memory> #include <tbb/tbb.h> class node_maker { public: using node = std::shared_ptr<tbb::flow::function_node<double, double, tbb::flow::rejecting>>; node_maker() { m_graph = std::make_shared<tbb::flow::graph>(); } std::size_t make_node(const std::size_t id) { auto op = [](const double d) { return d + 1; }; node n = std::make_shared<tbb::flow::function_node<double, double, tbb::flow::rejecting>>(*m_graph, 1, op, tbb::flow::rejecting(), 1); m_cache[id] = n; return id; }; private: std::unordered_map<std::size_t, node> m_cache; std::shared_ptr<tbb::flow::graph> m_graph; }; int main(int argc, char* argv[]) { node_maker maker; std::size_t n = maker.make_node(1); return 0; };
死锁发生的remove_node函数代码
inline void graph::remove_node(graph_node *n) { { spin_mutex::scoped_lock lock(nodelist_mutex); __TBB_ASSERT(my_nodes && my_nodes_last, "graph::remove_node: Error: no registered nodes"); if (n->prev) n->prev->next = n->next; if (n->next) n->next->prev = n->prev; if (my_nodes_last == n) my_nodes_last = n->prev; if (my_nodes == n) my_nodes = n->next; } n->prev = n->next = nullptr; }
调试模式下构造函数执行情况
调试模式下构造函数可正常执行,程序会进入include\oneapi\tbb\flow_graph.h中的以下构造函数:
//! Constructor // input_queue_type is allocated here, but destroyed in the function_input_base. // TODO: pass the graph_buffer_policy to the function_input_base so it can all // be done in one place. This would be an interface-breaking change. template< typename Body > __TBB_requires(function_node_body<Body, Input, Output>) __TBB_NOINLINE_SYM function_node( graph &g, size_t concurrency, Body body, Policy = Policy(), node_priority_t a_priority = no_priority ) : graph_node(g), input_impl_type(g, concurrency, body, a_priority), fOutput_type(g) { fgt_node_with_body( CODEPTR(), FLOW_FUNCTION_NODE, &this->my_graph, static_cast<receiver<input_type> *>(this), static_cast<sender<output_type> *>(this), this->my_body ); }
内容的提问来源于stack exchange,提问作者Vero
相关产品推荐
相关产品推荐

