My wild guess, based on reading the source, is that your compilation environment does not match the environment used to compile the libstdc++ binaries you're using. Specifically, libstdc++ was compiled without _GTHREAD_USE_COND_INIT_FUNC
, and it is defined in your environment.
Here is the reason: the header <condition_variable>
defines a data member of a type which resolves to pthread_cond_t
. If the macro __GTHREAD_COND_INIT
is defined, the default initialization for this member is specified in the header, and the constructor is defaulted in the implementation file. If it's not, it is initialized with a function call in the body of a non-default constructor. Whether __GTHREAD_COND_INIT
is defined is controlled by the _GTHREAD_USE_COND_INIT_FUNC
macro.
If in-class member initialization is implemented in G++ the way I think it is, e.g. the in-class initializers are executed before calling the constructor, then the effect you see would occur when your libstdc++ was compiled with _GTHREAD_USE_COND_INIT_FUNC
undefed, while right now it is defined in your environment somewhere. This means that the header does not provide in-class initialization and the default constructor from the library is used, leading to an uninitialized value.
Source references, in case you want to dig deeper:
- https://github.com/mirrors/gcc/blob/master/libstdc%2B%2B-v3/include/std/condition_variable
- https://github.com/mirrors/gcc/blob/master/libstdc%2B%2B-v3/src/c%2B%2B11/condition_variable.cc
- https://github.com/mirrors/gcc/blob/master/libgcc/gthr.h
- https://github.com/mirrors/gcc/blob/master/libgcc/gthr-posix.h