comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@avercom.net>
Subject: Re: Pragma Volatile
Date: Sat, 29 Sep 2001 13:38:58 -0400
Date: 2001-09-29T17:36:18+00:00	[thread overview]
Message-ID: <3BB60733.4A80708A@avercom.net> (raw)
In-Reply-To: 3BB10D52.4D455DBA@raytheon.com



Mark Johnson wrote:

> "Jon R. Harshaw" wrote:
>
> > OK. - Since I can't find a reference for this in my limited
> > documentation, what does "Pragma Volatile" do?  I'm guessing that it is
> > just available while the process that invokes it is up and running, but
> > that's just a WAG...

> ...

>
> A caution, after reading a number of articles on caches & memory
> visibility, I am not so sure the compiler vendors are putting enough care
> into enforcing the last restriction. In general, caches can reorder or
> combine writes which could violate that restriction. If you use volatile
> in conjunction w/ protected units and objects, you are probably OK. This
> is really a system dependent problem & I would need a lot more information
> about what you are trying to do [and why] to determine if you would have
> this problem.

The primary purpose of "volatile" is to warn the compiler that
the associated memory location might be read or updated
asynchonously by some other process or device.

There shouldn't be any problem if you are using this in a mono-processor.
On a multi-processor without synchronized caches, you can get into
trouble, but the onus is probably on the programmer to make sure
that variables shared between processors are placed in uncached
memory.  The compiler may not know enough about your
environment to arrange for that.

Certainly if the memory is shared with an I/O device, then it is
almost certainly uncached.

Another way to think about "volatile" is that you are asking the
compiler to not "cache" within registers the value of the memory
location, and instead always operate directly on the memory location.
In a multiprocessor environment, you would ideally like the compiler
to arrange for the memory not to be cached (in an unsynchronized
cache) by the hardware either, but as mentioned above, the compiler
may not have enought information or control over the hardware
environment to ensure that.


>
> --Mark

-Tucker Taft  stt@avercom.net




  reply	other threads:[~2001-09-29 17:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-25 14:07 Pragma Volatile Jon R. Harshaw
2001-09-25 14:23 ` David C. Hoos
2001-09-25 14:38 ` Marin David Condic
2001-09-25 23:03 ` Mark Johnson
2001-09-29 17:38   ` Tucker Taft [this message]
2001-09-29 18:22     ` minyard
2001-09-29 22:28       ` Jeffrey Carter
2001-09-30 13:10         ` Robert Dewar
2001-09-30 21:19           ` Jeffrey Carter
2001-10-01  2:58             ` minyard
2001-10-02  9:38           ` AG
2001-10-02 10:59             ` Jeff Creem
2001-09-30  2:03       ` DuckE
2001-09-30 13:01       ` Robert Dewar
2001-09-30 20:12         ` minyard
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox