[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Library initialization with gettext is not thread-safe

From: Vivien Kraus
Subject: Re: Library initialization with gettext is not thread-safe
Date: Fri, 08 Jul 2022 18:07:27 +0200
User-agent: Evolution 3.42.1

Le vendredi 08 juillet 2022 à 07:33 +0200, Bruno Haible a écrit :
> The 'bindtextdomain' function is multi-thread safe and idempotent.
> Therefore the libfoo_initialize function [1] is multi-thread safe and
> idempotent as well. That is, in the case that multiple threads call
> create_foo at the same time, libfoo_initialize may be called several
> times, but this is harmless.
> No?
I may be wrong, but I think that reading libfoo_initialized (in
create_foo) while another thread is modifying it (in libfoo_initialize)
is undefined behavior, even for a bool.

Having thought about it a bit more, I have found 2 solution:
- Use an atomic variable for libfoo_initialized;
- Use pthread_once.

However, atomic variables are quite a recent addition to C so I’m not
sure it can be advertised in the manual. And I don’t know much about
pthread_once, I don’t know whether it works if create_foo is called
from competing threads from different threading libraries (such as 2
openmp threads for instance).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]