[ ... ]
But how does it get "munged?"
By being written as a number of operations instead of a single atomic
one. I thought I'd already mentioned the situation with an x86 writing
to a 4 byte value at an odd address. It writes it in three separate bus
operations -- a single byte write, a two byte write, and finally a
single byte write.
Writing two bytes to an odd address (with the same processor) happens in
two operations.
On other machines, especially if a boolean is stored in a single byte,
we run into a different problem: most RISCs (for example) can't read or
write anything smaller than a whole (32-bit) word. To modify only one
byte, the read the whole word, modify it, then write back the result --
again, a non-atomic operation unless (expensive and non-portable) bus
locks are used to make it atomic.
In the specific case of a boolean, most of these problems are likely to
be covered up by the fact that in a boolean, only one bit is really
significant. The rest of the storage unit in which the boolean is
stored may be modified non-atomically, but it's difficult for the
modification of one bit to be non-atomic.
OTOH, I don't think there's any requirement or guarantee that a boolean
be stored as a single bit -- an implementation might (for example) store
0 and 0xffff for false and true respectively. In this case, if it reads
what's supposed to be a boolean, but happens to contain (for example)
0x00ff, it might decide something is defective, and halt the program
entirely. I'm not sure such an implementation exists, but I'm far from
certain it can't either.
Btw, the fact that this is obvious hasn't stopped people from arguing
it, and flabbergasting me.
I think most people have taken for granted that if a variable is being
modified, the intent is that it be available for reading later --
there's no point in writing a value if you're certain it will never be
used.