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. Marc