volatile (in comp.lang.c)

Ray Dunn ray at micomvax.UUCP
Mon May 30 23:56:22 AEST 1988


In article <1988May23.003847.1114 at 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



More information about the Comp.lang.c mailing list