金庆的专栏

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  423 随笔 :: 0 文章 :: 454 评论 :: 0 Trackbacks
# std::thread 中的异常会丢失调用栈

(金庆的专栏 2019.9)

主函数中的异常生成core文件能看到调用栈,
但是 std::thread 子线程中的异常生成 core 文件的调用栈如下:

```
Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7f18f00ab700 (LWP 32340)]
0x00007f19007335f7 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007f19007335f7 in raise () from /lib64/libc.so.6
#1  0x00007f1900734ce8 in abort () from /lib64/libc.so.6
#2  0x00007f19010379d5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6
#3  0x00007f1901035946 in ?? () from /lib64/libstdc++.so.6
#4  0x00007f1901035973 in std::terminate() () from /lib64/libstdc++.so.6
#5  0x00007f190108c2b5 in ?? () from /lib64/libstdc++.so.6
#6  0x00007f19012e7dc5 in start_thread () from /lib64/libpthread.so.0
#7  0x00007f19007f41cd in clone () from /lib64/libc.so.6
(gdb)
```

调用栈丢失使调试无法找到问题点。

据说 GCC 8 修正了该问题。

参考:
* [C++ uncaught exception in worker thread](https://stackoverflow.com/questions/48535100/c-uncaught-exception-in-worker-thread)
* [Bug 55917 - Impossible to find/debug unhandled exceptions in an std::thread](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55917)
posted on 2019-09-26 17:19 金庆 阅读(1532) 评论(0)  编辑 收藏 引用 所属分类: 1. C/C++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理