Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!im4u!ut-sally!utah-cs!utah-gr!uplherc!sp7040!obie!wes From: wes@obie.UUCP (Barnacle Wes) Newsgroups: comp.lang.c Subject: Re: Volatile is Necessary Message-ID: <102@obie.UUCP> Date: 30 Mar 88 18:28:06 GMT References: <12578@brl-adm.ARPA> <1988Mar25.172355.348@utzoo.uucp> <8107@sol.ARPA> Organization: the Well of Souls Lines: 26 Summary: Volatile also useful in... In article <8107@sol.ARPA>, crowl@cs.rochester.edu (Lawrence Crowl) writes: > 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. The `volatile' qualifier is also a must for such things as I/O processors that do not produce interrupts. Typically with such a device, you will poll the status register at a predetermined interval, and when the operation is complete, you can go on to the next operation on that device. These types of devices are used quite a bit in imbedded systems where the speed of the device is not critical, and the interrupt(s) are already heavily used for speed-critical devices/operations. You certainly don't want the compiler to optimize away your check on the status register! -- /\ - "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