Revision: 648
http://assorted.svn.sourceforge.net/assorted/?rev=648&view=rev
Author: yangzhang
Date: 2008-04-01 20:38:37 -0700 (Tue, 01 Apr 2008)
Log Message:
-----------
added test of exceptions in threads
Added Paths:
-----------
sandbox/trunk/src/cc/thread_exceptions.cc
Added: sandbox/trunk/src/cc/thread_exceptions.cc
===================================================================
--- sandbox/trunk/src/cc/thread_exceptions.cc (rev 0)
+++ sandbox/trunk/src/cc/thread_exceptions.cc 2008-04-02 03:38:37 UTC (rev 648)
@@ -0,0 +1,29 @@
+// Question: what happens when you throw an exception from a thread?
+// Answer: at least on Linux in g++, it turns out that an uncaught exception
+// causes the whole process to exit. One person in ##c++ says that this has
+// undefined behavior.
+
+#include <iostream>
+#include <pthread.h>
+#include <boost/bind.hpp>
+#include <commons/boost/threads.h>
+
+using namespace boost;
+using namespace commons;
+using namespace std;
+
+void
+f()
+{
+ cout << "throwing an exception\n" << endl;
+ throw 0;
+}
+
+int
+main()
+{
+ pthread_t t = checkpass(spawn(bind(f)));
+ pthread_join(t, NULL);
+ cout << "survived" << endl; // We never get here.
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|