Bug 15228

Summary: C++ exceptions+threads SIGABRTs.
Product: Base System Reporter: rcarter
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.0-CURRENT   
Hardware: Any   
OS: Any   

Description rcarter 1999-12-02 18:20:01 UTC
	Throwing a c++ exception across threads causes core dump.

Fix: 

None yet.
How-To-Repeat: 
$ c++ -pthread -D_THREAD_SAFE ex_test.cpp
$ ./a.out
Throwing Ex:
Caught Ex, now rethrowing it...
Caught Ex thrown from main thread.
Throwing Ex:
Caught Ex, now rethrowing it...
Abort trap (core dumped)
$

ex_test.cpp:

#include <stdio.h>
#include <pthread.h>

class Ex {};

class testEx {
public:
  void throwEx () {
    fprintf(stderr, "Throwing Ex:\n");
    throw Ex (); 
  }
};

void *
f(void *)
{
  testEx thetest;
  thetest.throwEx ();
}

void *
g(void *arg) 
{  
  try {
    f(arg);
  } catch (Ex &ex) {
    fprintf(stderr, "Caught Ex, now rethrowing it...\n");
    throw;
  }
}

int
main (void)
{
  int *arg = 0;
  
  try {
    g((void *) arg);
  } catch (Ex &ex) {
    fprintf(stderr, "Caught Ex thrown from main thread.\n");
  }
  
  pthread_t ex_thread;
  pthread_attr_t *attr = 0;
  
  try {
    pthread_create(&ex_thread, attr, g, (void *) arg);
  } catch (Ex &ex) {
    fprintf(stderr, "Caught Ex thrown from child thread.\n");
  }
  pthread_join(ex_thread, (void **) &arg);
  
  return 0;
}
Comment 1 Daniel Eischen freebsd_committer freebsd_triage 2000-11-18 05:02:37 UTC
State Changed
From-To: open->analyzed

I don't think this is a valid problem.  The test program 
creates a thread from the main program and expects the 
exception raised from the thread to be thrown back to the 
main program.  A thread is a separate execution context 
totally disjoint from the creator (until the time that 
the creator or another thread join to it). 

I am going to close this PR in a week or two if I don't 
here back from the originator.
Comment 2 Daniel Eischen freebsd_committer freebsd_triage 2000-12-05 04:07:27 UTC
State Changed
From-To: analyzed->closed

Does not seem to be a valid bug and exhibits desired behaviour. 
No response from originator since analyzed over 2 weeks ago.