From: Daniel Arndt Date: Tue, 24 Jan 2023 04:10:16 +0000 (-0500) Subject: Make ensure_kokkos_initialized thread-safe X-Git-Tag: v9.5.0-rc1~618^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ffc2e491a7996fad6ed69040b5578756669fb93c;p=dealii.git Make ensure_kokkos_initialized thread-safe --- diff --git a/source/base/kokkos.cc b/source/base/kokkos.cc index 7cf0a34d6a..5ea3b374c1 100644 --- a/source/base/kokkos.cc +++ b/source/base/kokkos.cc @@ -31,9 +31,14 @@ namespace internal { if (!Kokkos::is_initialized()) { - dealii_initialized_kokkos = true; - Kokkos::initialize(); - std::atexit(Kokkos::finalize); + // only execute once + static bool dummy = [] { + dealii_initialized_kokkos = true; + Kokkos::initialize(); + std::atexit(Kokkos::finalize); + return true; + }(); + (void)dummy; } } } // namespace internal