GNU backtrace_symbols() 和 dladdr() 是线程安全的吗?
我正在编写一个 C++ 异常类,它必须在抛出站点提供有限的回溯。由于我的应用程序将是多线程的,因此可能会同时引发异常。我在网上搜索了这个线程安全问题,但没有找到。
backtrace()
返回 C 字符串数组。应用程序不得释放这些 C 字符串。由于它获取信息并在运行时合成这些字符串,我担心它不是线程安全的。
dladdr()
返回一个 struct Dl_info
,其中包含两个 C 字符串。也不能被应用程序释放。
哦,好吧,我想我应该阅读源代码。
I am writing a C++ exception class, which has to provide limited backtrace at throw site. Since my application will be multi-threaded, exceptions might be thrown at the same time. I searched the Internet for this thread-safety issue, but found none.
backtrace()
returns array of C strings. These C strings must not be freed by the application. Since it gets its information and composites these strings at runtime, I fear that it is not thread safe.
dladdr()
returns a struct Dl_info
, with two C strings in it. Also must not be freed by the application.
Oh well, I guess I should just read the source code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自手册
看起来他们正在使用线程本地存储。
dladdr
返回属于已加载目标文件的不可修改字符串。这是线程安全的,因为它是只读的,并且该对象在dlclose
之前可用。From the manual
Looks like they're using thread-local storage.
dladdr
is returning non-modifiable strings which belong to the loaded object file. This is thread-safe because it's read-only and the object is available untildlclose
.