Boost logo

Boost Users :

From: Brian Plummer (bplummer_at_[hidden])
Date: 2006-01-04 19:26:37

The following simple program seg faults. (I have boiled it down to the
bare essentials to product the fault:

#include <boost/thread.hpp>

void * MMULT2(void);
void * MMULT2CalcMaster(void);

int main(void) {

class MMULT2ThreadClass {
void calculate(void) {}
public :
    MMULT2ThreadClass() {}
    void operator ()() { calculate(); }

void * MMULT2CalcMaster(void) {
    int numThreads = 2;
    boost::thread_group threads;
    for (int i = 0; i < numThreads; ++i)

void * MMULT2(void) {
    return MMULT2CalcMaster();

Here is the compile line:

cd /SDE/common/src/lib/PSF/PSFWorkbook/testing/BoostThreadProblem/
make clean run DEBUG=YES
/bin/rm -rf DO/LINUX_X86_GCC3.4.5/debug/BoostThreadProblem.o
/SDE/common/bin/LINUX_X86_GCC3.4.5/debug/BoostThreadProblem *.o *.i
Templates.DB gcc -I. -I/SDE/common/include
-I/usr/java/jdk1.3.1_01/include -I/usr/java/jdk1.3.1_01/include/linux
-I/opt/sybase-11.9.2/include -c -g -DDEBUG -D_TRACE -DLITTLEENDIAN=1
-o DO/LINUX_X86_GCC3.4.5/debug/BoostThreadProblem.o
gcc DO/LINUX_X86_GCC3.4.5/debug/BoostThreadProblem.o -L/usr/local/lib
-lboost_thread-gcc-mt-d-1_33_1 -o
make: *** [run] Segmentation fault

Compilation exited abnormally with code 2 at Wed Jan 4 17:12:11

I have tried using the -pthread and -D_REENTRANT compile flags with no
luck. I had previously used the code that this example is based on,
without any problems under 1.30.0 (and not using the -pthread and
-D_REENTRANT flags). I feel I've got to be missing something very basic
associated with building and using the Thread library.

At this point I'm a bit stumped.

Also, I noticed the following. bjam -sTOOLS=gcc in the build directory
only builds the mt_d version of the library and not the release version.
   I don't remember needing to do anything special to get both versions

Additionally, I'm not having any of these problems with the same code on
WIN32 with Visual Studio 2003.

Thanks in advance,

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at