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

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
As a workaround you can add this non-static data member to your
BackgroundThread class:

namespace Logger
{
  class EXPORT BackgroundThread
  {
    // ...
    std::chrono::tzdb_list::const_iterator tzdb =
std::chrono::get_tzdb_list().begin();
  };
}

The iterator contains a shared_ptr which shares ownership with the chrono::tzdb
at the front of the tzdb_list. While that iterator exists, the tzdb object will
not be destroyed even if the global shared_ptr inside libstdc++ is destroyed.
(This is a GCC extension, the C++ standard doesn't require this behaviour of
the iterator extending the tzdb lifetime).

If you update the system's zoneinfo (i.e. tzdata) files and then call
chrono::reload_tzdb() while the application is running, then subsequent calls
to chrono::get_tzdb_list() will access a different instance of chrono::tzdb,
and the const_iterator will not extend the lifetime of the correct chrono::tzdb
object. You can update the iterator to refer to the new front of the list if
needed.

Reply via email to