volatile isn't necessary, but it's there

Stephen J. Friedl friedl at vsi.UUCP
Sat Apr 16 11:30:01 AEST 1988


In article <144 at obie.UUCP>, wes at obie.UUCP (Barnacle Wes) writes:
> In article <48767 at sun.uucp>, guy at gorodish.Sun.COM (Guy Harris) writes:
> | It is worth noting, for example, that there is no guarantee that "++mutex"
> | is an atomic operation.
> | [SPARC uses three instructions: load+inc+store]
> 
> Another good reason NOT to use a SPARC for anything other than a
> paperweight.  On a reasonable processor like the M68000, `++mutex'
> becomes an atomic operation like `addq #1,mutex'.

     A single instruction is no guarantee of atomicity either.
The VAX allows an increment instruction -- "INC mutex" -- but it
is not necessarily atomic; you need ADAWI (Add Aligned Word,
Interlocked) for that.  The VAX provides a half a dozen
instructions like this, designed for synchronized shared access,
and the docs say they are needed.  The WE32100 (in the AT&T 3B2)
has SWAPBI (swap bytes interlocked) instructions to do the same
kind of thing, so I surmise that instructions are not atomic
either.

     I know nothing about how the Moto works, but with today's
high-performance pipelined processors sharing memory with so many
kinds of other processors (DMA, I/O, math, etc.), relying on all
instructions being atomic is probably naive; it will just be
harder to track down where the mutex bugs are.

-- 
Steve Friedl   V-Systems, Inc.   "Yes, I'm jeff at unh's brother"
friedl at vsi.com  {backbones}!vsi.com!friedl  attmail!vsi!friedl



More information about the Comp.lang.c mailing list