OpenSolaris

Printable Version Enter a New Search
Bug ID 6611808
Synopsis pthread_once() intializer triggers GCC warning
State 10-Fix Delivered (Fix available in build)
Category:Subcategory library:header
Keywords standards | xen
Responsible Engineer Roger Faulkner
Reported Against
Duplicate Of
Introduced In solaris_2.5
Commit to Fix snv_100
Fixed In snv_100
Release Fixed solaris_nevada(snv_100)
Related Bugs 6751602
Submit Date 1-October-2007
Last Update Date 8-October-2008
Description
Compile:

#include <pthread.h>

pthread_once_t o = PTHREAD_ONCE_INIT;

$ gcc -Wall a.c
a.c:3: warning: missing braces around initializer
a.c:3: warning: (near initialization for `o.__pthread_once_pad')

PTHREAD_ONCE_INIT should be { { 0, 0, 0, 0 } } not { 0, 0, 0, 0 }
Note that this fix will break any code using the workaround:

#define       PTHREAD_ONCE_INIT       { {0, 0, 0, 0} }
/* workaround */
pthread_once_t o = { PTHREAD_ONCE_INIT };

I don't have a better idea though.
John Levon wrote:

> You observed:
>     Note that this fix will break any code using the workaround.
>     I don't have a better idea though.
> 
> I'm OK with this risk, since the fix is correct
> according to standards (and the old code wasn't).
> Tell me what you think.  How much open source pain will I cause?

We need to make this change. It will break our xVM build (where I found
the bug) but that's not a major problem. As for the rest of the pain,
see:

http://www.google.com/codesearch?hl=en&lr=&q={\s%3FPTHREAD_ONCE_INIT\s%3F}&sbtn=Search

It doesn't actually look too bad. It's probably worth a full SFW compile
though, and a flag day of course.

cheers,
john
I did a bringover and build of the SFW gate.
There were no problems with the change.
It turns out that there are no instances of either
'pthread_once_t' or PTHREAD_ONCE_INIT anywhere in the SFW gate.
Work Around
pthread_once_t o = { PTHREAD_ONCE_INIT };
Comments
N/A