Skip to content

Commit

Permalink
[bugfix] optimize windows threadpool destroy order, thanks Ryan.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunelFeng committed Mar 4, 2023
1 parent 1f57223 commit 6d491e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int main() {
* Thanks to the recommendation from [awesome-cpp](https://github.com/fffaraz/awesome-cpp), we all know, it is the most authoritative recommendation list for cpp project in the world
* Thanks to the recommendation from `Taskflow Group`: [awesome-parallel-computing](https://github.com/taskflow/awesome-parallel-computing), and we always treat [taskflow](https://github.com/taskflow/taskflow) as a role model
* Thanks to the recommendation from [awesome-workflow-engines](https://github.com/meirwah/awesome-workflow-engines)
* 感谢 [@yangyuxiang77](https://github.com/yangyuxiang77) [@logerrors](https://github.com/logerrors) [@whenever5225](https://github.com/whenever5225) [@May-Yaha](https://github.com/May-Yaha) [@Codesire-Deng](https://github.com/Codesire-Deng) [@yeshenyong](https://github.com/yeshenyong) [@MirrorYuChen](https://github.com/MirrorYuChen) [@HanYa](https://github.com/CodingHanYa) 等朋友(以贡献时间先后为序)为项目做出的贡献
* 感谢 [@yangyuxiang77](https://github.com/yangyuxiang77) [@logerrors](https://github.com/logerrors) [@whenever5225](https://github.com/whenever5225) [@May-Yaha](https://github.com/May-Yaha) [@Codesire-Deng](https://github.com/Codesire-Deng) [@yeshenyong](https://github.com/yeshenyong) [@MirrorYuChen](https://github.com/MirrorYuChen) [@HanYa](https://github.com/CodingHanYa) [@Ryan](https://github.com/ryanhuang) 等朋友(以贡献时间先后为序)为项目做出的贡献
* 感谢所有为`CGraph`项目提出的意见和建议的朋友,在此不一一提及。随时欢迎大家加入,一起共建

</details>
Expand Down
12 changes: 9 additions & 3 deletions src/UtilsCtrl/ThreadPool/UThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@ CStatus UThreadPool::destroy() {
for (auto &pt : primary_threads_) {
status += pt->destroy();
}
CGRAPH_FUNCTION_CHECK_STATUS

for (auto &pt : primary_threads_) {
/**
* 这里之所以 destroy和 delete分开两个循环执行,
* 是因为当前线程被delete后,还可能存在未被delete的主线程,来steal当前线程的任务
* 在windows环境下,可能出现问题。
* destroy 和 delete 分开之后,不会出现此问题。
* 感谢 Ryan大佬(https://github.com/ryanhuang) 提供的帮助
*/
for (auto &pt : primary_threads_) {
CGRAPH_DELETE_PTR(pt)
}

CGRAPH_FUNCTION_CHECK_STATUS
primary_threads_.clear();

// secondary 线程是智能指针,不需要delete
Expand Down
2 changes: 0 additions & 2 deletions src/UtilsCtrl/UAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

CGRAPH_NAMESPACE_BEGIN

static std::mutex g_session_mtx;

/**
* 仅用于生成CObject类型的类
*/
Expand Down

0 comments on commit 6d491e6

Please sign in to comment.