使用 async 和 future 在 linux 上抛出异常(gcc 4.8.4)
Using async and future is throwing exception on linux (gcc 4.8.4)
我有一段简单的代码,它在不应该抛出异常时抛出异常。
所有适当的 headers 都包含在内,并且程序构建没有错误。下面的代码。执行result1.get()时出现异常;
有人可以告诉我我做错了什么吗?
在此先感谢您的帮助。
int func1 ()
{
return 0;
}
int main()
{
future<int> result1(async(func1));
int result = result1.get();
return 0;
}
运行 程序的结果是这样的:
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
将 -pthread
添加到编译器标志。不确定细节,但出于某种原因 gcc 4.8 给出了 Unknown error -1
如果它被遗漏了(但是,至少恕我直言,它应该警告你没有启用线程或给出一些链接错误而不是编译并在运行时抛出)。
我有一段简单的代码,它在不应该抛出异常时抛出异常。 所有适当的 headers 都包含在内,并且程序构建没有错误。下面的代码。执行result1.get()时出现异常; 有人可以告诉我我做错了什么吗? 在此先感谢您的帮助。
int func1 ()
{
return 0;
}
int main()
{
future<int> result1(async(func1));
int result = result1.get();
return 0;
}
运行 程序的结果是这样的:
terminate called after throwing an instance of 'std::system_error'
what(): Unknown error -1
将 -pthread
添加到编译器标志。不确定细节,但出于某种原因 gcc 4.8 给出了 Unknown error -1
如果它被遗漏了(但是,至少恕我直言,它应该警告你没有启用线程或给出一些链接错误而不是编译并在运行时抛出)。