Boost logo

Boost Users :

From: Matthew Edwards (matthew.edwards_at_[hidden])
Date: 2007-05-08 14:38:06


I am experiencing some strange errors in a multi-threaded environment on MAC OS X, dual core. I am receiving segfaults, bus errors and illegal instruction crashes regularily with simple calls to boost::format operations. Disabling one of the cores on my machine will completely remove the errors (just fyi). If I add a mutex lock around the calls to boost::format in my sample code (inside the for loop of threadRun) then no problems occur.

The following code can be used to reproduce the crash. It occurs perhaps one out of every 10 runs. It can crash (viewed by CrashReporter) in multiple places, mainly in ::parse(), and operator%.

I compile with -O0. If it would help, I can post the logs from CrashReporter.

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/format.hpp>

#define NUM_THREAD 10
#define NUM_ITER 100

void threadRun()
{
   for( int i = 0; i < NUM_ITER; i++ )
   {
      boost::format fmt( "format %1% %2% %3%" );
      fmt % "Some message" % 10 % "another str";
   }
}

int main()
{
  boost::thread *threads[NUM_THREAD];

  for( int i = 0; i < NUM_THREAD; i++ )
  {
    threads[i] = new boost::thread( &threadRun );
  }

  for( int i = 0; i < NUM_THREAD; i++ )
   {
      threads[i]->join();
      delete( threads[i] );
   }
 
   return 0;
}

Regards,

Matthew



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