Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: volatile isn't necessary, but it's there Message-ID: <1988Apr16.224255.15760@utzoo.uucp> Organization: U of Toronto Zoology References: <7794@alice.UUCP> <48767@sun.uucp>, <144@obie.UUCP> Date: Sat, 16 Apr 88 22:42:55 GMT > | 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