[英]segmentation fault using static libraries with std::jthread (g++-10)
I'm developing a library that works with std::jthread
(new in C++20) using g++ 10.0.1.我正在使用 g++ 10.0.1 开发一个与
std::jthread
(C++20 中的新功能)一起使用的库。 The library works fine if I compile it using share libraries, but If I compile it with static libraries I got a segmentation fault at the end of the program (thread destructor).如果我使用共享库编译它,该库工作正常,但如果我使用 static 库编译它,我在程序结束时遇到分段错误(线程析构函数)。 I have narrowed down my test case to a simple thread creation and join:
我已将我的测试用例缩小到一个简单的线程创建和连接:
#include <iostream>
#include <thread>
int main(int argc, const char** argv) {
auto t = std::jthread([]() { std::cout << "OK\n"; });
t.join();
return 0;
}
To compile I use:要编译我使用:
g++-10 -o test --static -std=c++20 test.cc -lpthread
And running it:并运行它:
% ./test
zsh: segmentation fault (core dumped) ./test
There any one has an idea what this problem could be?有谁知道这个问题可能是什么?
Update:更新:
Following @JérômeRichard suggested reference, I was able to compile and run my little test program without problem按照@JérômeRichard 建议的参考,我能够毫无问题地编译和运行我的小测试程序
g++-10 -o test --static -std=c++20 test.cc -lrt -pthread -Wl,--whole-archive -lpthread -Wl,--no-whole-archive
However, changing the code to use request_stop
instead of join
the program is segmenting fault again ( https://godbolt.org/z/obGN8Y ).但是,将代码更改为使用
request_stop
而不是join
程序会再次出现分段错误( https://godbolt.org/z/obGN8Y )。
#include <iostream>
#include <thread>
int main() {
auto t = std::jthread([]{ std::cout << "OK" << std::endl; });
t.request_stop();
}
The problem was reported to libstdc++ ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95989 ) and a patch has been generated to solve the problem.该问题已报告给 libstdc++ ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95989 ),并且已生成补丁来解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.