C 11异步SEG故障
c++11 Async seg fault
我只是尝试使用GCC 4.7.2的新的C 11功能,尽管当我去运行SEG故障时。
$ ./a.out
Message from main.
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
Aborted (core dumped)
我用GCC的" beta"功能编译为C 0x,with:
g++ -std=c++11 c11.cpp
代码:
#include <future>
#include <iostream>
void called_from_async() {
std::cout << "Async call" << std::endl;
}
int main() {
//called_from_async launched in a separate thread if possible
std::future<void> result( std::async(called_from_async));
std::cout << "Message from main." << std::endl;
//ensure that called_from_async is launched synchronously
//if it wasn't already launched
result.get();
return 0;
}
我相信这会发生这种情况,因为您忘记了与Posix Threads库链接。只需将-pthread
或-lpthread
添加到g++
标志,问题就应该消失。
如果您对详细信息感兴趣,则会发生这种情况,因为C 11运行时仅在使用这些功能的情况下才能在运行时解决pthread
的符号。因此,如果您忘了链接,运行时将无法解决这些符号,将您的环境视为不支持线程并抛出异常(您不会捕获,并且它逐渐删除了您的申请)。
相关文章:
- C++函数过载会导致 SEG 故障
- 带升压的 SEG 故障::make_shared / 特征3 内存.h.
- C ;使用lambdas在类中有条件地扩展功能(MWE的SEG故障)
- lambda回调中Android Cocos2D-X应用程序上的SEG故障
- 访问索引指向向量元素时的seg故障 - 做错了什么
- 如何修复strlen seg故障
- 将内存分配给指针数组时SEG故障
- MPI Hello World上的Valgrind SEG故障
- 迭代器越来越多,并导致SEG故障
- 复制CORBA ::任何包含字符串的corba程序SEG故障
- 当有1个以上的对象时,动态字符串类断裂与SEG故障
- C AVX2:访问数组数组中的地址时SEG故障
- SEG故障取决于指针分配的顺序
- 为什么C 线引起SEG故障
- std::map 的比较器函数中的 SEG 故障/未定义行为
- C/C++ 字符串错误与 ARM SEG 故障总线错误
- Taglib设置专辑图片,但给出了SEG故障
- 低内存会导致本机代码中的SEG故障
- STD上的SEG故障::设置整数插入
- SEG故障仅发生每次跑步