Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix graph processnode destruction bug #33

Open
Discovery-Kingdom opened this issue Nov 28, 2024 · 0 comments
Open

Fix graph processnode destruction bug #33

Discovery-Kingdom opened this issue Nov 28, 2024 · 0 comments

Comments

@Discovery-Kingdom
Copy link

以下代码存在析构bug
void Node::Stop() {
if (!m_run) {
return;
}
m_run = false;
std::for_each(m_input_buffers.begin(), m_input_buffers.end(),
[&](const auto &item) { item.second->clear(); });
std::for_each(m_output_buffers.begin(), m_output_buffers.end(),
[&](const auto &item) { item.second->clear(); });
m_base_cond->notify_all();
if (m_worker.joinable()) {
m_worker.join();
}
if (exit_cb) {
exit_cb(getName(), StatusCode::NodeExit, "节点线程退出");
}
std::cout << getName() << " exit" << std::endl;
}

void Node::worker() {
while (m_run) {
auto datas = get_input_datas();
if (!datas->batch_data.empty()) {
if (batch_data_handler_hooker) {
auto res = batch_data_handler_hooker(datas);
send_output_datas(res);
continue;
}
auto &batch_data = datas->batch_data;
for (auto &data : batch_data) {
if (data_handler_hooker) {
data = data_handler_hooker(data);
} else {
data = handle_data(data);
}
send_output_data(data);
}
} else {
std::unique_lockstd::mutex lk(m_base_mutex);
m_base_cond->wait(lk);
continue;
}
}
}

修复方式
void Node::Stop() {
if (!m_run) {
return;
}
{
std::unique_lockstd::mutex lk(m_base_mutex);
m_run = false;
}
std::for_each(m_input_buffers.begin(), m_input_buffers.end(),
[&](const auto &item) { item.second->clear(); });
std::for_each(m_output_buffers.begin(), m_output_buffers.end(),
[&](const auto &item) { item.second->clear(); });
m_base_cond->notify_all();
if (m_worker.joinable()) {
m_worker.join();
}
if (exit_cb) {
exit_cb(getName(), StatusCode::NodeExit, "节点线程退出");
}
std::cout << getName() << " exit" << std::endl;
}

void Node::worker() {
while (m_run) {
auto datas = get_input_datas();
if (!datas->batch_data.empty()) {
if (batch_data_handler_hooker) {
auto res = batch_data_handler_hooker(datas);
send_output_datas(res);
continue;
}
auto &batch_data = datas->batch_data;
for (auto &data : batch_data) {
if (data_handler_hooker) {
data = data_handler_hooker(data);
} else {
data = handle_data(data);
}
send_output_data(data);
}
} else {
std::unique_lockstd::mutex lk(m_base_mutex);
if(!m_run)
{
break;
}
m_base_cond->wait(lk);
continue;
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant