This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]