Skip to main content
gamedev.net
🔒 Locked

boost::thread and exceptions c++

Started by Ingrater 4 replies 1.8k views
Original Post
Ingrater
Ingrater
As far as I read in the boost documentation it is safe to use exceptions in threads as long as they are catched in the same thread. So I wrote this small test Programm, but it crashes for me (mingw gcc 3.4.5, boost 1.36)
#include <boost/thread/thread.hpp>
#include <boost/ref.hpp>

void throw_something(){
  int ex = 1;
  throw ex;
}

struct dummy {
  void operator ()(){
    while(true){
      try{
        throw_something();
      }
      catch(...){}
    }
  }
};

int main()
{
    dummy t1,t2;
    
    printf("Starting threads\n");
    boost::thread thread2(boost::ref(t2));
    t1();

    return 0;
}

I'm totaly despaired. I've searched for hours, and googeld but couldn't find anything. Can someone please enlighten me? Thanks in advance Ingrater
http://3d.benjamin-thaut.de
NotAYakk
NotAYakk
Do you have more details than "it crashed"?

A stack trace? An error message?
MaulingMonkey
MaulingMonkey
Works fine here with VS2008 + boost 1.37 -- enters an infinite loop of course.

Any particular reason you're using MinGW instead of the free and generally superior VS2008 Express Edition?
Ingrater
Ingrater
it crashes inside of __Unwind_SjLj_RaisException()

if found out that -mthreads should be used for compiling and linking to get thread safe exceptions. Unfortunately those options have absolutely no effect for me...

[Edited by - Ingrater on February 27, 2009 12:42:30 AM]
http://3d.benjamin-thaut.de
the_edd
the_edd
Did you compile the boost libraries with exact same compiler you're using now?

MinGW comes in two flavours. Each compiles code using a different exception handling mechanism (SJLJ or DWARF). If you're linking objects of different types, you'll run in to trouble.
Ingrater
Ingrater
I've found out, that I've linked a lib to the app (lua) that was not compiled with the -mthreads option. So the threadsafe exception handling could not be enabled. After I removed the lib from the linking process everything worked fine.
http://3d.benjamin-thaut.de

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.