From: Bruno Haible Date: Fri, 4 Aug 2023 12:50:04 +0000 (+0200) Subject: readutmp: Ensure multithread-safety. X-Git-Tag: v1.0~964 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=525dc1d17d273ed6b38afa09b778fb5752366bfe;p=gnulib.git readutmp: Ensure multithread-safety. * lib/readutmp.c (get_boot_time): Initialize 'cached' after 'boot_time', not before. Also declare both as volatile. --- diff --git a/ChangeLog b/ChangeLog index dc30f193f0..7e9c04111e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-08-04 Bruno Haible + + readutmp: Ensure multithread-safety. + * lib/readutmp.c (get_boot_time): Initialize 'cached' after 'boot_time', + not before. Also declare both as volatile. + 2023-08-04 Bruno Haible readutmp tests: Fix gcc warning (regression from yesterday). diff --git a/lib/readutmp.c b/lib/readutmp.c index c692b3854d..01c02ad36e 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -152,13 +152,13 @@ get_boot_time_uncached (void) static struct timespec get_boot_time (void) { - static bool cached; - static struct timespec boot_time; + static bool volatile cached; + static struct timespec volatile boot_time; if (!cached) { - cached = true; boot_time = get_boot_time_uncached (); + cached = true; } return boot_time; }