volatile isn't necessary, but it's there

Barnacle Wes wes at obie.UUCP
Mon Apr 11 05:08:28 AEST 1988


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.  It is, in fact, worth noting that even if "extern
| volatile char mutex;" was used, there would be no guarantee that "++mutex"
| is atomic.  In all cases, for example, "++mutex" takes an instruction to
| load "mutex" into a register, an instruction to increment it, and an
| instruction to store it, on a SPARC.  The same would be true of any other
| architecture lacking an instruction performing an "add 1 to memory"
| operation.

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'.

| This is a real problem; there were some mildly entertaining bugs on Sun-4
| caused by statements such as "++mutex;" in the kernel not being surrounded by
| "spl" calls.

Did you get these bugs squashed, or will you relase the Sun-4 SunOS
with them intact?
-- 
    /\              -  "Against Stupidity,  -    {backbones}!
   /\/\  .    /\    -  The Gods Themselves  -  utah-cs!utah-gr!
  /    \/ \/\/  \   -   Contend in Vain."   -  uplherc!sp7040!
 / U i n T e c h \  -       Schiller        -     obie!wes



More information about the Comp.lang.c mailing list