Hi Marc, > C11 has introduced atomic types and atomic operations. When they are not > available, one can use locks/mutexes instead. > > It would be nice if there was a Gnulib module that abstracts over this, > much like the threadlib module and friends abstract over a specific > threading implementation. > > What I am thinking of is the following: Given a type T, a new Gnulib module > atomic allows the declaration of an atomic version of type T. This is > straightforward on a platform that has <stdatomic.h>. Otherwise the atomic > version of T would be a struct consisting of an object of type T together > with a lock. > > The rest of the module would then provide some simple atomic primitives > like fetch_and_add, etc. that are either mapped to the C11 stdatomic > counterparts or are implemented using the lock.
Yes, given that the platform support for these atomic types/operations is increasing, it would accelerate the adoption if there was a Gnulib module, like you describe it. Program developers could then adopt <stdatomic.h> without losing portability to a number of platforms. Personally I'm not very motivated to work on that (because in most algorithms I've seen, mutexes/locks are the way to go, and because I find the memory_order stuff hard to understand). But if you want to work on that, it will be welcome! Bruno