volatile isn't necessary, but it's there

Henry Spencer henry at utzoo.uucp
Sun Apr 17 08:42:55 AEST 1988


> | It is worth noting, for example, that there is no guarantee that "++mutex"
> | is an atomic operation...
> 
> ... On a reasonable processor like the M68000, `++mutex'
> becomes an atomic operation like `addq #1,mutex'.

Hee hee.  You haven't read the hardware specs for the 68000 carefully.
The ADDQ instruction does two bus cycles, and as I recall it there is no
guarantee that something else (like, say, another processor) can't get
the bus in between.  If I recall correctly, the *only* read-modify-write
instruction that is *guaranteed* atomic on the 68000 is TAS, which is odd
enough that compilers are most unlikely to generate it.  (Actually the
atomicity of even TAS is somewhat subject to hardware details, but it has
a much better chance of being atomic than ADDQ.)
-- 
"Noalias must go.  This is           |  Henry Spencer @ U of Toronto Zoology
non-negotiable."  --DMR              | {ihnp4,decvax,uunet!mnetor}!utzoo!henry



More information about the Comp.lang.c mailing list