C11 atomic implementation

C11 specifies a number of language features for atomic support. Essentially, it implements the C++ template library with language features, and enhances them to include floating point and complex support for basic arithmetic operations. Please consult the C11 standard for all the nitty gritty details.

How It Oughta Work

The basic approach is

Current Status

A set of patches have been created and applied to the branch C11-atomic which provide most of the infrastructural changes required. This consists of

I do not plan to complete this work right now, and will consider picking it up again in 2014 if no one else gets to it first. Someone with front end experience would proabbly be able to do this much much quicker.

What Needs Doing


There were a couple of threads where Joseph Myers reviewed these patches. I have adjusted them based on his comments, with a couple of un-addressed exceptions which I will list afterwards. The threads are found at:

Original Atomic type patch

Previous state plus I made some adjustments based on JSM's followup, but none of his broader comments, just typeos and simple things were addressed.

The patches which have been applied to the C11-atomic branch are as follows:


rev 202891

New Branch Sept 25 2013


rev 202916

Alignment target hook


rev 202917

Add ME/BE atomic type support


rev 202919

Add _Atomic and __attribute__((atomic))


rev 202920

Add __attribute__((atomic)) to C++ atomic templates.  Add tests.


rev 202959

Add functionality to expand atomic variable lval and rvals into calls.


rev 202960

Make typeof() an atomic variable return the main variant.


rev 202961

Add stdatomic.h header file.

Also provided here is an un-applied patch from the original patch set. It changes all the built in atomic functions to take 'volatile atomic *' as the first parameter rather than the current "volatile *". This solves the compilation problem in libstdc++-v3, but upon relfection I dont think the type should be changed. It possible to revert this decision again by adding this patch, and dealing with what happens when the types arent atomic. The cast from type to the atomic version of that type should be allowed as long as size and alignment match. Otherwise a warning should be issued. When we get around to changing the size of an atoic object someday (if ever), we'll have to decide what to do when the size of the non atomic DOESNT match the type being passed in.. we may need to issue wrapper code adn temps to make it work for existing code... anyway, can of worms to open later.

I supplied the patch her e so it doesn't get lost.


not applied

Change __atomic first params to 'volatile atomic *'.

Any questions, please contact me Andrew MacLeod amacleod@redhat.com

None: Atomic/C11 (last edited 2013-09-30 15:10:20 by AndrewMacLeod)