MinGW and threads

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

MinGW and threads

Janne Kätevä
Hi

I have noticed that on Ubuntu my code that uses Boost Threads works fine
when I throw exceptions (for example strings) and catch them in the same
thread. But this doesn't seem to work on Windows XP with Mingw gcc
3.4.5. If I throw a exception in thread, the program crashes. Is there
some known problem with threads and Mingw? I'm using Boost 1.37.

Simple example:

#include <stdexcept>
#include <boost/thread/thread.hpp>

using namespace std;

class callable {
public:
   void run() {
       try {
           cout << "Throwing" << endl;
           throw string("error");
       } catch(string &e) {
           cout << "Error: " << e << endl;
       }
   }

   void operator()() {
       this->run();
   }
};

class callable2 {
public:
   void run() {
       try {
           cout << "Throwing2" << endl;
           throw string("error2");
       } catch(string &e) {
           cout << "Error2: " << e << endl;
       }
   }

   void operator()() {
       this->run();
   }
};

int main() {
   callable c1;
   callable2 c2;
   boost::thread thrd1(boost::ref(c1));
   boost::thread thrd2(boost::ref(c2));

   thrd1.join();
   thrd2.join();

   return 0;
}

And I compile and link the code with following commands:

g++ -IC:\Boost\boost_1_37_0 -O0 -g3 -Wall -c -fmessage-length=0
-mthreads -oThread.o ..\Thread.cpp
g++ -IC:\Boost\boost_1_37_0 -O0 -g3 -Wall -c -fmessage-length=0
-mthreads -omain.o ..\main.cpp
g++ -LC:\Boost\boost_1_37_0\stage\lib --enable-thread-safety
-oThread.exe main.o Thread.o -llibboost_thread-mgw34-mt-1_37

Janne

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: MinGW and threads

Earnie Boyd

Quoting Janne Kätevä <[hidden email]>:

>
> g++ -IC:\Boost\boost_1_37_0 -O0 -g3 -Wall -c -fmessage-length=0
> -mthreads -oThread.o ..\Thread.cpp
> g++ -IC:\Boost\boost_1_37_0 -O0 -g3 -Wall -c -fmessage-length=0
> -mthreads -omain.o ..\main.cpp
> g++ -LC:\Boost\boost_1_37_0\stage\lib --enable-thread-safety
> -oThread.exe main.o Thread.o -llibboost_thread-mgw34-mt-1_37
>

Google for mingw+thread and see if you can find references to -mthread.

Earnie

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.
Reply | Threaded
Open this post in threaded view
|

Re: MinGW and threads

Danny Smith
In reply to this post by Janne Kätevä

> g++ -LC:\Boost\boost_1_37_0\stage\lib --enable-thread-safety
> -oThread.exe main.o Thread.o -llibboost_thread-mgw34-mt-1_37

Try adding -mthreads in link step.

Danny


------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.