[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.
>
>Jeff
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).
David
- [avr-gcc-list] "Volatile", Keith Gudger, 2005/04/15
- Re: [avr-gcc-list] "Volatile", E. Weddington, 2005/04/15
- Re: [avr-gcc-list] "Volatile", David Brown, 2005/04/17
- Re: [avr-gcc-list] "Volatile", Jeff Epler, 2005/04/17
- Re: [avr-gcc-list] "Volatile",
David Brown <=
- Re: [avr-gcc-list] "Volatile", Graham Davies, 2005/04/18
- Re: [avr-gcc-list] "Volatile", David Brown, 2005/04/18
- Re: [avr-gcc-list] "Volatile", Keith Gudger, 2005/04/18
- Re: [avr-gcc-list] "Volatile", David Brown, 2005/04/18
- Re: [avr-gcc-list] "Volatile", David Kelly, 2005/04/18
- Re: [avr-gcc-list] "Volatile", David Brown, 2005/04/19
- RE: [avr-gcc-list] "Volatile", stevech, 2005/04/20
- Re: [avr-gcc-list] "Volatile", Colin Paul Gloster, 2005/04/20
- Re: [avr-gcc-list] "Volatile", E. Weddington, 2005/04/20
- Re: [avr-gcc-list] 'Volatile', Mike Murphree, 2005/04/20