|
Boost Users : |
Subject: [Boost-users] Thread crash on interruption mingw
From: Chris Spencer (spencercw_at_[hidden])
Date: 2010-02-03 17:35:18
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I'm having some trouble with the thread library. When I interrupt a
thread it is causing my application to crash.
Here is a simple test file:
#include <boost/thread.hpp>
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#endif
using namespace boost;
using namespace boost::posix_time;
using namespace std;
void threadFunction() {
try {
boost::this_thread::sleep(seconds(10));
} catch (thread_interrupted&) {
cerr << "interrupted" << endl;
}
}
int main() {
thread myThread(threadFunction);
#ifdef _WIN32
Sleep(1000);
#else
sleep(1);
#endif
myThread.interrupt();
myThread.join();
return 0;
}
If I compile this on Linux, or on Windows with MSVC it works perfectly
every time, but if I compile with mingw it *usually* crashes after
printing 'interrupted'. If I put a sleep in between the interrupt and
join though it never crashes, so there appears to be a race condition
somewhere..
Compiled with: i386-pc-mingw32-g++ -mthreads thread_test.cpp
- -lboost_thread -o thread_test.exe
$ i386-pc-mingw32-g++ --version
i386-pc-mingw32-g++ (GCC) 4.4.3
Boost version 1.42
Any help would be appreciated.
Chris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAktp+iAACgkQ6iqRtkAADZiiWwCgrd3R/G2yCstU0ruuipCPbISo
IAcAoOCE93g+alGcSUf7ZedHYC7Mwq3u
=BHbA
-----END PGP SIGNATURE-----
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net