From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,148d39ae0d22411d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-29 10:36:19 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!cambridge1-snf1.gtei.net!news.gtei.net!inmet!not-for-mail From: Tucker Taft Newsgroups: comp.lang.ada Subject: Re: Pragma Volatile Date: Sat, 29 Sep 2001 13:38:58 -0400 Organization: AverStar Message-ID: <3BB60733.4A80708A@avercom.net> References: <3BB08F9C.BFB01047@raytheon.com> <3BB10D52.4D455DBA@raytheon.com> NNTP-Posting-Host: 209-6-249-6.c3-0.lex-ubr1.sbo-lex.ma.cable.rcn.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" Content-Transfer-Encoding: 7bit X-Trace: inmet2.burl.averstar.com 1001784978 6788 209.6.249.6 (29 Sep 2001 17:36:18 GMT) X-Complaints-To: usenet@inmet2.burl.averstar.com NNTP-Posting-Date: 29 Sep 2001 17:36:18 GMT X-Mailer: Mozilla 4.75C-CCK-MCD {C-UDP; EBM-APPLE} (Macintosh; U; PPC) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:13516 Date: 2001-09-29T17:36:18+00:00 List-Id: 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