This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

g++ 3.4.4, mingw32, exceptions and threads

I am having problems getting exceptions to work properly in 
the latest release of g++ distributed from cygwin.   I have a multithreaded
code which is built using the no-cygwin option.   The code uses
exceptions in a few places.  Oddly the code is either crashing out right,
or the exceptions are being delivered to the wrong thread.   

My search for answers through this archive and the web have
been in fruitless.   The keywords "thread" and "exception" are used
too frequenty for other uses.  I have been unable to find anyone responding
to similar reports on other mailling lists.   What I have found dates to 
the egcs days and is really not relevent.  

This is obviously a case where the mingw32 libgcc has been built
without threadsafe exceptions.  My question is there an option to compile
mingw32 with threadsafe exception support?  Are there plans to 
release a threadsafe compiled version in cygwin?  If there is a way
to build the libgcc and no plans for cygwin to release it,  where do I find 
instructions on how to build it with threadsafty myself? 

I have included an example below.  It appears to work without the
-mno-cygwin option.  With that option, it either runs incorrectly, crashes,
or exits unexpectly depending on the phase of the moon.


#include <iostream>
#include <exception>
#include <Windows.h>

HANDLE thread_=0; 
int thread_go(void *) {
  for (int i=0;i<40 ; i++) {
    try {
      throw std::exception();
    catch (std::exception& e) {
      std::cout << "Caught std::exception" << std::endl;
    catch(...) {
      std::cout <<"Unhandled Exception" << std::endl;

int main() {
  thread_=::CreateThread(NULL,0, (LPTHREAD_START_ROUTINE) thread_go, 0, 0, NULL); 
  try {
    throw int(10);
  catch (int i) {
    std::cout << "main: caught int " << i << std::endl;
  catch (...) {
    std::cout << "main: unexpected exception to main!" << std::endl;
  std::cout << "sleep" << std::endl;
  std::cout << "done" << std::endl; 

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]