簡體   English   中英

使用帶有 std::jthread (g++-10) 的 static 庫的分段錯誤

[英]segmentation fault using static libraries with std::jthread (g++-10)

我正在使用 g++ 10.0.1 開發一個與std::jthread (C++20 中的新功能)一起使用的庫。 如果我使用共享庫編譯它,該庫工作正常,但如果我使用 static 庫編譯它,我在程序結束時遇到分段錯誤(線程析構函數)。 我已將我的測試用例縮小到一個簡單的線程創建和連接:

#include <iostream>
#include <thread>

int main(int argc, const char** argv) {
  auto t = std::jthread([]() { std::cout << "OK\n"; });
  t.join();
  return 0;
}

要編譯我使用:

g++-10 -o test --static -std=c++20 test.cc -lpthread 

並運行它:

% ./test
zsh: segmentation fault (core dumped)  ./test

有誰知道這個問題可能是什么?

更新:

按照@JérômeRichard 建議的參考,我能夠毫無問題地編譯和運行我的小測試程序

g++-10 -o test --static -std=c++20 test.cc -lrt -pthread  -Wl,--whole-archive -lpthread -Wl,--no-whole-archive

但是,將代碼更改為使用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();
}

該問題已報告給 libstdc++ ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95989 ),並且已生成補丁來解決該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM