Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2004-10-05 08:55:55


On Tue, Oct 05, 2004 at 03:05:13PM +0200, Markus Sch?pflin wrote:

> When compiling the smart pointer tests with gcc 3.4.2 on Tru64, two tests
> fail with an error message. (See http://tinyurl.com/4jngu )
>
> As far as I can see, the shared pointer implementation at some point
> includes the "pthread.h" system header file but gcc on Tru64 requires that
> -pthread must be specified on the command line when including this header
> file.
>
> When running this test with gcc 3.4.2 on Linux the file "pthread.h" is also
> included but gcc doesn't require the addition of -pthread in the command
> line on this platform.
>
> This leads to the question whether it is ok to include "pthread.h" without
> specifying -pthread on the command line. Does anyone know an answer to this?

Short answer: yes, it's OK.

Long answer:

On Linux, with GCC, yes, it's fine. libstdc++ does this itself. When
configured to use pthreads (*) the library includes gthr-posix.h, which
unconditionally includes pthread.h

At link time, if -pthread wasn't given, the pthread_xxx() symbols
declared in pthread.h aren't found and so the linker falls back to weak
symbols defined in the libstdc++ library (which are just stubs that do
nothing).

I'm not so sure about other POSIX platforms, just Linux.

jon

(*) N.B. configuring the compiler to use threads does NOT mean you
always compile with pthreads, it means you have the _option_ of
compiling with -pthread. If the compiler isn't configured to use threads
then you can't use -pthread at all.

-- 
"Live fast, die old, and make very sure everyone knows you were there."
	- Alan Cox

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk