
On Mon, May 10, 2004 at 12:14:59PM +0200, Christoph Ludwig wrote:
The problem turns out to be that gcc 3.4 defines the preprocessor variable _REENTRANT if certain standard library headers are included even if the compiler is *not* called with the '-pthread' command line option.
I believe this is only when GCC is configured with posix threads (either explicitly with --enable-threads=posix, or implicitly on POSIX systems where the default threading model is pthreads). If you explicitly configure with --enable-threads=single (or the equivalent --disable-threads) then _REENTRANT won't be defined, and boost/config.hpp correctly detects that threads are disabled. This doesn't help solve your problem, of course.
The following test exhibits this behavior and shows that it causes BOOST_HAS_THREADS to be erroneously defined in boost/config/suffix.hpp if, e.g., the standard header string is included:
[snip]
I have no idea what the gcc developers recommend in order to detect multi-threading support or if this should be reported to the gcc developers as a bug. But it will certainly break many programs using Boost.
I've been meaning to get around to asking that on the gcc list. Unfortunately gcc.gnu.org seems to be down today. GCC provides the inline __gthread_active_p() to tell if if the program is linked to the pthread library, but I don't know how to give the same info to the preprocessor at compile time.
A user can work around this problem by either including boost/config.hpp before any other headers (even Boost headers since boost/lexical_cast.hpp, for example, includes string before boost/config.hpp). Or the user builds everything with MT-support, even if the program itself is single threaded. Neither workaround is satisfying.
Or (as I've been doing) explicitly defining BOOST_DISABLE_THREADS when you know your program is single threaded.
PS: FWIW, I could trace back the problem to a change in include/c++/i686-pc-linux-gnu/bits/gthr-default.h. This change was discussed in http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01607.html.
FWIW the google cache version of that is here: http://tinyurl.com/2xksr jon -- "He who joyfully marches to music in rank and file has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would fully suffice." - Albert Einstein