Path: utzoo!yunexus!geac!daveb From: daveb@geac.UUCP (David Collier-Brown) Newsgroups: comp.lang.c Subject: Re: volatile (in comp.lang.c) Summary: Sidebar on atomicity Keywords: volatile atomic Message-ID: <2849@geac.UUCP> Date: 9 Jun 88 11:58:44 GMT Article-I.D.: geac.2849 References: <20345@pyramid.pyramid.com> <833@mcdsun.UUCP> <1988May23.003847.1114@utzoo.uucp> <1078@micomvax.UUCP> <4922@ihlpf.ATT.COM> Reply-To: daveb@geac.UUCP (David Collier-Brown) Organization: The Geac Nit-Picking Department Lines: 52 In article <1988May23.003847.1114@utzoo.uucp> (Henry Spencer) writes: | Unfortunately, this is not sufficient. "Volatile" does not guarantee | that operations are atomic. It is entirely possible for x and/or y to | contain trash because they caught the variable midway through the | assignment. In article <4922@ihlpf.ATT.COM> nevin1@ihlpf.UUCP (00704a-Liber,N.J.) writes: | C itself does not guarantee that access to any particular data type, | including char, is atomic. My question is: is there *any* use for 'volatile' | which does not require 'atomicity' at some level? If not, then 'volatile' | doesn't really fix any of the problems we have without it. I suspect that, historically, C merely assumed that accesses to atomic (pardon the pun) data types were atomic, and accesses to composite ones were non-atomic. This tends to make a volatile declaration sufficient in the two "old" cases: 1) A device register, because the register was integer-width[1], because the device-register-changer part of the device handshook with the memory-access hardware, because the memory-access hardware[2] mediated no simultaneous accesses from simultaneously-running processors[3] and two processes could not be running simultaneously on the same processor. 2) A signal handler, because a user process and a signal handler could not be switched between in the "middle" of an access to a memory location, and two processes could not be running at the same time on the same processor. If one makes a minimum set of restrictions on device registers and signal-handlers part of the language/runtime specification, volatile is sufficient. If one does not, it isn't. This of course does not deal with the harder problem of multiprocessors. In fact, it was not even sufficient for some of the first micros, who had to have their device registers polled by an interrupt handler/driver to see when the "valid to read" bit was on (:-{). --dave (volatile is an engineering tradeoff, not an elegant invention) c-b [1] Character-width on micros. [2] One of the XXX-bus controllers on DEC equipment, the system controller on Honeybuns. [3] Then a rara avis. Disclaimer: the authors of the language may disagree about details, corrections are invited. -- David Collier-Brown. {mnetor yunexus utgpu}!geac!daveb Geac Computers Ltd., | "His Majesty made you a major 350 Steelcase Road, | because he believed you would Markham, Ontario. | know when not to obey his orders"