https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118811

--- Comment #22 from Nicholas Williams <nicholas at nicholaswilliams dot net> 
---
(In reply to Jonathan Wakely from comment #20)
> Because the constructors for globals in the libstdc++.so shared library are
> run before the ones in your program. This happens when the shared library is
> loaded into the process.
> 
> When you link to libstdc++.a all the globals are in the same executable and
> the order of global constructors is unspecified (I think it depends on the
> order that the linker processes the various .o objects in the link, but
> formally the C++ standard says it's unspecified).

(In reply to Jonathan Wakely from comment #21)
> https://maskray.me/blog/2021-11-07-init-ctors-init-array covers it in as
> clear a way as I've seen.

Brilliant! That makes perfect sense. Thank you.

(In reply to Jonathan Wakely from comment #12)
> As a workaround you can add this non-static data member to your
> BackgroundThread class:
> ...
>     std::chrono::tzdb_list::const_iterator tzdb =
> std::chrono::get_tzdb_list().begin();

This indeed did stop the problem in our internal code. We'll see if it makes it
through code review. :-)

Thanks!

Reply via email to