bug-gnulib
[Top][All Lists]
Advanced

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

Module suggestion: Atomic operations


From: Marc Nieper-Wißkirchen
Subject: Module suggestion: Atomic operations
Date: Sun, 24 May 2020 15:36:19 +0200

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

reply via email to

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