This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Make generic atomicity.h use gthr.h mutexes
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- To: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org, phil at jaj dot com
- Date: Sun, 10 Nov 2002 15:17:54 -0500 (EST)
- Subject: Re: Make generic atomicity.h use gthr.h mutexes
> Something like this? (I haven't tried to test it on a dynamic-init system,
> since I haven't figure out how to fake one yet.)
Don't think the approach will work.
> static inline _Atomic_word
> __attribute__ ((__unused__))
> __exchange_and_add (volatile _Atomic_word* __mem, int __val)
> {
> - _Atomic_word __result;
> +#ifndef __GTHREAD_MUTEX_INIT
> + static bool __initialized = false;
> + if (!__initialized)
> + {
> + __GTHREAD_MUTEX_INIT_FUNCTION (_Atomic_add_mutex);
> + __initialized = true;
> + }
> +#endif
> +
> + _Atomic_word __result;
__initialized is local to the each inline copy of __exchange_and_add,
so each copy will attempt to initialize _Atomic_add_mutex. Even if
__initialized was global, there could be race conditions in initializing
_Atomic_add_mutex.
Dave
--
J. David Anglin dave.anglin@nrc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6605)