当我读到有关 g++-4.9
中改进的链接时间优化支持时,我想试一试。可悲的是,我在运行时遇到异常,特别是 std::system_error
和 e.what() == Enable multithreading to use std::thread: Operation not permitted
.
现在我通常知道如何修复该错误:将 -pthread
添加到我的编译器调用中,但事实上,我已经有了这个参数!
我的示例代码是:
#include <thread>
int main()
{
std::thread t([](){}); // do nothing in a thread!
t.join(); // wait for nothing to be done
}
编译为(X 为 7、8 或 9)
g++-4.X -std=c++11 -pthread test.cpp -o thread_test_fine
按预期完美运行,没有运行时错误。
但是,
g++-4.X -std=c++11 -pthread -flto test.cpp -o thread_test_runtime_error
因 system_error
异常而失败。
问题:
此行为是有意为之(修复方法是什么?)还是错误?
(在这个问题出现之前:我的编译器都是用--enable-threads=posix
构建的)
最佳答案
关于c++ - 链接时间优化与多线程支持冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24264364/