异步与Visual Studio 2013(Windows8.1)和GCC 4.9(Ubuntu14.10)的不同行为(Different behavior of async with Visual Studio 2013(Windows8.1) and GCC 4.9(Ubuntu14.10))
async在Windows VS和Linux g ++中具有不同的行为(实现)。
我用以下代码测试了它:
void Func1(){sleep(1000*1000);} void Func2(){sleep(1000*2);throw runtime_error("An expected exception");} int main(int argc, char* argv[]){ try{ auto f1 = async(launch::async, Func1); auto f2 = async(launch::async, Func2); f2.get();//block here f1.get(); }catch (exception& e){ printf("exception: %s\n", e.what()); } return 0; }
Func1在发射后会长时间睡眠。
Func2将抛出异常。
我的观察是:
在Windows中,异常立即传播,主线程(程序)将相应地捕获它。
在Linux中,异常被保持,并且程序在Func1中的休眠1000秒结束之前不会退出。
所以在Linux中有人知道,如何让程序立即捕获异常并退出程序?
async has different behavior(implementation) in Windows VS and Linux g++.
I tested it with the following code:
void Func1(){sleep(1000*1000);} void Func2(){sleep(1000*2);throw runtime_error("An expected exception");} int main(int argc, char* argv[]){ try{ auto f1 = async(launch::async, Func1); auto f2 = async(launch::async, Func2); f2.get();//block here f1.get(); }catch (exception& e){ printf("exception: %s\n", e.what()); } return 0; }
Func1 sleeps for a long time after launch.
Func2 is to throw an exception.
My observation is:
In Windows, the exception is propagated immediately and the main thread(program) will catch it exit accordingly.
In Linux, the exception is held on and the program doesn't exit until the sleep 1000 seconds in Func1 is over.
So does anybody know in Linux, how to make the program catch the exception immediately and exit the program??
原文:https://stackoverflow.com/questions/30698207
最满意答案
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如何从远程计算机(而不是localhost)访问MySQL?(How to access MySQL from a remote computer (not localhost)?)[2022-03-23]
好的,请注意这让世界和他的狗可以访问您的mysql服务器。 GRANT ALL ON *.* to '%'@'%' WITH GRANT OPTION; 但是说你在192.168.1.2/16的家庭网络上,那么你至少可以像这样限制它。 GRANT ALL ON *.* to '%'@'192.168.%' WITH GRANT OPTION; 另一个选择是你有一个用户和密码,但想要从任何地方连接 GRANT ALL ON *.* to 'mysecretuser'@'%' IDENTIFIED BY ' ... -
psql的\命令由换行符终止,而不是分号。 有点疣IMO。 因此,您需要在命令中添加换行符。 在shell中引用的文字中允许使用文字换行符,因此您可以将它们插入到命令中,但最好只在本地使用here-document并通过ssh的stdin将其发送到psql的stdin。 但是仍然会将输出保留在远程计算机上: ssh rmsasi@hj$i "psql $dbname $username" << __EOF__ \o | cat >> $FILE_OUT SELECT * from component wh ...
-
首先,错误消息确实会有所帮助。 根据评论,我会说我怀疑你正在连接到正确的服务器。 但是,您使用的是“root”用户名? 这样的用户名出现在Postgres上是非常不寻常的。 第一个是放置文件的位置。 这应该放在您的Web服务器的文档根目录或cgi bin中,具体取决于您配置的内容(可能是前者)。 对于第二个问题,请仔细检查用户名和密码,并确保您可以通过pgAdmin III使用这些用户名和密码连接到同一个数据库。 如果事情不正确,确保您拥有正确的凭据将使您的代码更容易进行故障排除。 First, error ...
-
根据您的要求有多复杂,您可以使用libssh (LGPL,用于各种ssh客户端),调查修改dropbear (MIT)或快速'n dirty: system("scp myfile host:/some/path/to/file"); Depending on how complex your requirements are, you could use libssh (LGPL, used in various ssh clients), investigate modifying dropbear ...
-
通过创建临时网络共享,我能够在这篇文章中找到答案。 效果很好! I was able to find the answer in this post - by creating a temporary network share. Works well!
-
您不需要(读取:“不得”)将您的路径用引号引起来。 deffilePath = "\\" & ipaddress & "\c$\" & deffileName You don't need to (read: "must not") enclose your path in quotes. deffilePath = "\\" & ipaddress & "\c$\" & deffileName
-
尝试使用sysinternal工具PSExec 它将允许您远程执行文件 Try to use the sysinternal tools PSExec It will allow you to remotely execute a file
-
此页面上的代码显示了如何使用不带域的身份验证进行连接。 请注意Windows XP上的“Force Guest”问题 。 There's code on this page that shows how to connect using authentication without a domain. Watch out for the the 'Force Guest' problem on Windows XP though.