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:24:00 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0



On 24/06/16 22:59, Jacob Moroni wrote:



Also, on a somewhat related note, I think there may be a bug in the
<avr/atomic.h> header, specifically, in the “__iRestore” function which is
called to restore the interrupt state after the atomic block is finished.
There’s currently a memory barrier after SREG is restored, but I think the
barrier should be before in order to ensure that any pending stores are
completed _before_ restoring the interrupt state. If the barrier is after,
I’m not sure if there’s anything preventing operations on non-volatile
variables from being reordered with respect to the restoring of SREG.


It has been a while since I looked at such things in detail, and I don't have the appropriate references conveniently available at the moment. But if I remember correctly, the change to the interrupt status is delayed in hardware for an instruction, so that it is safe to re-enable interrupts (restore the SREG) and then have the memory barrier.



It’s likely that this problem has never been encountered in the field
because the common practice is to declare all shared globals as “volatile”,
which therefore prevents accesses to them from being reordered with respect
to access of SREG, but it seems like a possible issue to me.



If you agree, I can submit a bug report or even make the fix myself once I
figure out the process of sending in a patch. This is actually my first
time participating in any type of collaborative open source project!





reply via email to

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