This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Are arrays guaranteed to be affected by a "memory" clobber?
- From: Martin Sebor <msebor at redhat dot com>
- To: Sebastian <sebastianspublicaddress at googlemail dot com>, gcc-help at gcc dot gnu dot org
- Date: Fri, 12 Jun 2015 14:40:46 -0600
- Subject: Re: Are arrays guaranteed to be affected by a "memory" clobber?
- Authentication-results: sourceware.org; auth=none
- References: <20150610224600 dot 00007d52 at unknown>
On 06/10/2015 02:46 PM, Sebastian wrote:
The gcc manual [1] only mentions "memory reads or writes to items other than those listed in the input and output operands", it doesn't mention anything about volatile qualifiers.
Now I wonder if array elements, too, must be qualified "volatile" if I want to access them from an ISR (Interrupt Service Routine) and from "normal" code.
The prototypical example that explains why volatile is important
is "normal" code spinning in a tight loop waiting for the ISR to
write some value to an object. It doesn't matter whether or not
the object is an element of an array. If the access to the object
isn't volatile the normal code may never see its value change.
So the volatile qualifier may not be necessary in the ISR but
is is essential outside of it. A barrier in the ISR won't help.
Martin