Xref: utzoo comp.lang.c:10519 comp.arch:5050 Path: utzoo!attcan!uunet!husc6!mailrus!ames!oliveb!pyramid!prls!philabs!micomvax!ray From: ray@micomvax.UUCP (Ray Dunn) Newsgroups: comp.lang.c,comp.arch Subject: Re: volatile (in comp.lang.c) Message-ID: <1078@micomvax.UUCP> Date: 30 May 88 13:56:22 GMT References: <20345@pyramid.pyramid.com> <833@mcdsun.UUCP> <1988May23.003847.1114@utzoo.uucp> Reply-To: ray@micomvax.UUCP (Ray Dunn) Organization: Philips Electronics Ltd. (TDS - Montreal) St. Laurent QC, Canada Lines: 27 Posted: Mon May 30 09:56:22 1988 In article <1988May23.003847.1114@utzoo.uucp> (Henry Spencer) writes: [quoting an article without attributing it] >> .... To get behaviour that is the same for all compilers, the >> variable v must be declared volatile. > >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. Fortunately this is sufficient when the programmer understands what he is programming, and chooses data types etc which will ensure atomicity, if that is what he is trying to achieve. Even in assembler, problems will result if a non-atomic instruction is used in a semaphore mechanism. All "volatile" gives in this shared memory context is a basic low level tool that a careful programmer can use to sufficiently handle this class of problems. All the compiler need be aware of is that a reference to a volatile variable must always generate a memory reference. -- Ray Dunn. | UUCP: ..!{philabs, mnetor}!micomvax!ray Philips Electronics Ltd. | TEL : (514) 744-8200 Ext: 2347 600 Dr Frederik Philips Blvd | FAX : (514) 744-6455 St Laurent. Quebec. H4M 2S9 | TLX : 05-824090