This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Are arrays guaranteed to be affected by a "memory" clobber?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]