Volatile is Necessary

Lawrence Crowl crowl at cs.rochester.edu
Mon Mar 28 04:51:27 AEST 1988


The `volatile' type qualifier of ANSI C has recently been criticized as a
frill.  While this assertion is arguable for uniprocessors, it is not true for
shared-memory multiprocessors.  Processes on such machines communicate via
updates to a shared variables.  These updates may occur at arbitrary times
relative to one of the observing processes.  If there is no mechanism to
indicate when a variable referenced by one process may be modified by another
process, the compiler must assume that all variables may be modified at any
time.  In other words, the compiler must assume that all variables are
`volatile'.  This limits the optimizing effectiveness of compilers
substantially.  This limitation is severe because most variables are not
shared.  The compiler is forced to use sub-optimial code for 99% of its
references in order to obtain correctness on the other 1%.  Shared-memory
multiprocessors need the `volatile' concept in order to use highly optimizing
compilers.  The `volatile' concept could be provided as a pragma, but the
concept must exist.  
-- 
  Lawrence Crowl		716-275-9499	University of Rochester
		      crowl at cs.rochester.edu	Computer Science Department
...!{allegra,decvax,rutgers}!rochester!crowl	Rochester, New York,  14627



More information about the Comp.lang.c mailing list