Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-10-11 09:35:45


William Kempf:
> --- In boost_at_y..., "George A. Heintzelman" <georgeh_at_a...> wrote:
> > Hi Boosters, and Boost threaders. I'm trying to make use of
> > Boost.Threads in a Solaris environment, compiling with g++-2.95.2
> > --pedantic. We have pthreads, but there are a few problems:
>
> The good news is that most of these are already known and I'm in the
> process of addressing them.
>
> > 1) (Less serious) the statement
> > pthread_once_t once = PTHREAD_ONCE_INIT ;
> >
> > (occurs twice) triggers a warning:
> > /work/nova/2465/once.cpp:27: warning: aggregate has a partly
> bracketed
> > initializer

[snip]
> This code is straight from the POSIX standard and so should work.
> However, if it's a known issue on a platform I'm not adverse to
> including work arounds for that platform. I just need more info on
> why this is occuring, what possible side effects the "fix" might
> cause to other platforms, and if we can use the Boost.Config system
> to fix only the broken platform. If you can answer these and give me
> a patch I'll move it into the base code.

I don't think I have a real patch. I was being somewhat hacky locally.
But I can tell you what the problem is.

I'm on a Solaris 2.8 machine, using g++-2.95.2. In the system headers,
we have the following definitions:

(in pthread.h)
#define PTHREAD_ONCE_NOTDONE 0
#define PTHREAD_ONCE_DONE 1
#define PTHREAD_ONCE_INIT {0, 0, 0, PTHREAD_ONCE_NOTDONE}

(in sys/types.h)

typedef struct _once {
        upad64_t __pthread_once_pad[4];
} pthread_once_t;

So, we're trying to initialize a struct with a single array member with
an array. They're slightly different things, so g++ complains. I don't
know if it would Do The Right Thing anyway, but I doubt it. As it turns
out, gcc also complains with a simple test program. Sun's own compiler
(perhaps unsurprisingly) fails to complain. This is probably a bug in
that compiler, but it probably Does The Right Thing.

Probably the right thing to do is patch the system headers so that
PTHREAD_ONCE_INIT is { { 0,0,0, PTHREAD_ONCE_NOTDONE } }. The
alternative in Boost is to wrap PTHREAD_ONCE_INIT in { } itself. This
works, but would have to be ifdef'd only for broken platforms, as it
will harm others. The other difficulty is, I don't know how far this
problem extends in Solaris, or whether other non-Solaris
implementations have the same problem... Probably just #ifdefing it
with Solaris tags (BOOST_PLATFORM == "sun") will work. I note that
Sun's compiler doesn't complain with either version.

George Heintzelman
georgeh_at_[hidden]


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