[Top][All Lists]

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

Re: [avr-gcc-list] "Volatile"

From: David Brown
Subject: Re: [avr-gcc-list] "Volatile"
Date: Mon, 18 Apr 2005 08:40:47 +0200

>On Sun, Apr 17, 2005 at 03:27:37PM +0200, David Brown wrote:
>> If your flag is declared as "volatile unsigned char flag", then
>> operations such as "flag = 0" and "flag = 1" are atomic.
>But is that a requirement of the standard, or simply because
>1-byte-wide stores are atomic on the AVR architecture?  I believe it's
>the latter.

Yes, it is the later - C has no concept of "atomic statement", so anything
dependant on atomicity is going to be target-depedendant and non-portable.
Disabling interrupts to create atomic sections is clearly non-portable.
Using a single byte like this is not guarenteed to be atomic by the C
standard, but it is portable in practice to most architectures.  I cannot
think of any sort of architecture, baring a Turing machine, that would
require read-modify-write to set a char to a constant value, since a char is
always directly addressible (on machines that can't directly address an
8-bit byte, a C "char" may be 16-bit or bigger).  It might not be
implemented by a single instruction, but the operation is atomic (given that
you interrupt routines preserve all registers).


reply via email to

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