avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] C11 Atomics and GCC libatomic


From: David Brown
Subject: Re: [avr-libc-dev] C11 Atomics and GCC libatomic
Date: Sun, 26 Jun 2016 20:32:20 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0



On 26/06/16 17:15, Georg-Johann Lay wrote:

There are quite some standard insns for atomics known to gcc, cf.
"atomic_" insns in

http://gcc.gnu.org/onlinedocs/gccint/Standard-Names.html

This can avoid overhead of function calls.  But I still don't see the
great advantage of using stdatomic over the "classical" util/atomic.h
from avr-libc.  For C++ we don't have portability because there is no
libstdc++ generated for avr, not even libsupc++...

Johann


The "classical" atomic locks in util/atomic.h are for constructing critical sections - sections of code that can only be accessed by one context of execution at a time. The stdatomic C11 and C++ atomics are for atomic data - variables that are accessed atomically regardless of contexts. These are two different ways of looking at atomic accesses and correct interrupt or multi-threaded programming. While either can be used to implement the other, they do not replace each other - the best choice depends on the type of code and the type of problem to be solved at the time.

Additionally, it is always good to implement standard solutions - it makes it a lot easier to write code that can be portable between different architectures. So implementing the C11 and C++11 atomics helps make avr-gcc a better tool.

avr-gcc supports a fair amount of C++, even though there are many parts missing (last I looked, which was a good while ago, support for exceptions was missing). People use C++ on the avr, and it makes a lot of sense to support as many features of the latest C++ standards as can conveniently be done. Of course there are many things in C++ that would be disproportionately hard to support on the AVR, and are unlikely to be much used - but if C++11 atomics can be supported "for free" by Jacob's functions added to libatomic to support C11 atomics, then that is a great thing.

mvh.,

David




reply via email to

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