Boost logo

Boost Users :

From: Alistair Potts (mailinglist_at_[hidden])
Date: 2006-07-12 14:20:48


Sure. Here's a very simple program that does nothing useful, but which
crashes consistently on a multi-processor machine.

Kind regards,
Alistair

#include <boost/regex.hpp>
#include <iostream>
#include <string>
#include <pthread.h>
 
const char* const reExpr("abcd(.*)");
const char* const replaceExpr("$1");
boost::regex re(reExpr);
 
size_t noThreads(50);
pthread_barrier_t barrier;
 
extern "C"
{
  void* test_fn(void*)
  {
    pthread_barrier_wait(&barrier);
    while(1)
    {
      std::string expr("abcdefgh");
      std::cout << boost::regex_replace(expr, re, replaceExpr,
boost::match_default|boost::format_all) << std::endl;
    }
    return 0;
  }
}
 
int main(int argc,char* argv[])
{
  pthread_t* threads = new pthread_t[noThreads];
  pthread_barrier_init(&barrier, NULL, noThreads);
 
  size_t i = 0;
  for (; i < noThreads; ++i)
  {
    if(pthread_create(&(threads[i]), NULL, test_fn, NULL))
    {
      std::cerr << "Error creating thread" << std::endl;
      return 1;
    }
  }
  for(i = 0; i < noThreads; ++i)
    pthread_join(threads[i], NULL);
 
  exit(0);
}

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of John Maddock
Sent: 11 July 2006 10:02
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] Seg faults when using
boost::regex_replaceinmultiple threads

mailinglist_at_[hidden] wrote:
>> Does anyone know if there is a known problem with using these new
>> versions of boost::regex_replace in multiple threads? If it's
>> helpful, I have a very simple test program that demonstrates the
>> problem. Any help on this would be greatly appreciated.

If you can let me have the test program I can at least try and reproduce it.

I must admit to being at a loss to explain this otherwise: there really is
no thread sensitive code inside regex_replace.

John.

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


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