Re: A basic question question about volatile use



Ark Khasin wrote:
I have a memory-mapped peripheral with a mapping like, say,
struct T {uint8_t read, write, status, forkicks;};

If I slap a volatile on an object of type struct T, does it guarantee that all accesses to the members are byte-wide, or is the compiler free
to read or read-modify-write in any data width it chooses?

Is slapping a volatile on each member of the struct definition any different? better? worse?

I guess you don't have a decent C book. The point of 'volatile' is to tell the compiler that this variable might be modified by forces outside this program's scope. Think memory-mapped I/O.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
.



Relevant Pages

  • [git patches] net driver updates #2
    ... struct sk_buff *skb, int ring_offset) ... +static int use_mcs; ... volatile u8 RCR; ...
    (Linux-Kernel)
  • Volatile, pthread mutexes, structure pointers, and non-locked reads
    ... It's unclear to me if I need to use volatile and/or add extra locking ... around a field of a struct to avoid the compiler optimizing away a read ... I've read that if I use locking around all accesses to a variable then ... pthread_mutex_unlock(globalMutex); ...
    (comp.programming.threads)
  • Re: [PATCH] LinuxPPS - definitive version
    ... volatile where you want it treated that way. ... The problem is that we can have several PPS sources into a system and ... members of struct pps_kinfo and struct pps_kparams. ... a pps_unregister_sourceruns while pps_eventexecutes on another ...
    (Linux-Kernel)
  • Re: [PATCH] LinuxPPS - definitive version
    ... Can you please explain better where should I put the 'volatile' ... members of struct pps_kinfo and struct pps_kparams. ... first glance I think your existing clients have that right (you have ...
    (Linux-Kernel)
  • Re: [patch] i386: make bitops safe
    ... invoking the bitop. ... is to add a memory clobber and tag all of them as volatile. ... the least costly way should be to make the "ADDR" define work ... struct fake_area { ...
    (Linux-Kernel)