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) {
    MMULT2();
}

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)
       threads.create_thread(MMULT2ThreadClass());
    threads.join_all();
}

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
-DDBG=1 -DDEVL=1 -DDBGPROP -D_UNIX
-DNEWPROPS -DBRP_LINUXINTEL -DBRP_LITTLE_ENDIAN BoostThreadProblem.cpp
-o DO/LINUX_X86_GCC3.4.5/debug/BoostThreadProblem.o
gcc DO/LINUX_X86_GCC3.4.5/debug/BoostThreadProblem.o -L/usr/local/lib
-L/usr/lib
-L/SDE/COTS/Boost/boost_1_33_1/bin/boost/libs/thread/build/libboost_thread.a/gcc/release/threading-multi
-lboost_thread-gcc-mt-d-1_33_1 -o
/SDE/common/bin/LINUX_X86_GCC3.4.5/debug/BoostThreadProblem
/SDE/common/bin/LINUX_X86_GCC3.4.5/debug/BoostThreadProblem
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
built.

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

Thanks in advance,
Brian


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