andrew732
July 31st, 2011, 11:48 PM
The code snippet below is the core of a function mythreadfunc() that is run concurrently for several threads using CreateThread() and WaitForMultipleObjects(). Everything seems to work fine except actually using boost::regex_match(). For example, if that line is changed to if(true), the entire multithreaded function works perfectly. Similarly, if mythreadfunc() as shown below is run "normally" without multiple threads, it works perfectly. But if mythreadfunc() as shown below is run with multiple threads, the entire program crashes with return value 0xc0000005 "access violation."
This leads me to believe that boost::regex is not thread safe, but according to the boost site, there aren't any bugs related to this issue for boost 1.45. As far as I can tell I'm using boost in thread safe mode (BOOST_HAS_THREADS is defined). I'm probably doing something really dumb related to MSVC threads or related to the way I configured boost, but I'm not sure what it is! Thanks for any ideas or help~
static const boost::regex expression("^[0-9]+");
ifstream myfile(x);
string line;
if(myfile.is_open())
{
while(myfile.good())
{
getline(myfile, line);
if(boost::regex_match(line, expression))
{
//do stuff
}
}
myfile.close();
This leads me to believe that boost::regex is not thread safe, but according to the boost site, there aren't any bugs related to this issue for boost 1.45. As far as I can tell I'm using boost in thread safe mode (BOOST_HAS_THREADS is defined). I'm probably doing something really dumb related to MSVC threads or related to the way I configured boost, but I'm not sure what it is! Thanks for any ideas or help~
static const boost::regex expression("^[0-9]+");
ifstream myfile(x);
string line;
if(myfile.is_open())
{
while(myfile.good())
{
getline(myfile, line);
if(boost::regex_match(line, expression))
{
//do stuff
}
}
myfile.close();