Re: Newbie question: accessing global variable on multiprocessor
- From: David Schwartz <davids@xxxxxxxxxxxxx>
- Date: Wed, 6 Feb 2008 13:07:02 -0800 (PST)
On Feb 6, 9:02 am, "Boris" <spa...@xxxxxxxxxx> wrote:
That doesn't help you. It doesn't provide specific, guaranteedhas guaranteed semantics.
semantics. Declaring that the object can be modified by another thread
doesn't mean that doing so without locks or Interlocked* operations
Basically, what I mean: 'volatile' can also be used for other purposes (than
multi-processing). For example, DMA transfer from some device (into memory).
I just thought that because of this semantics (of 'volatile' ),
implementations make sure that memory values are always used (as opposed to
cached values). I don't know if it's true or not, of course. Just wondering.
If you know for a fact that compiler optimizations are your only
issue, then 'volatile' may well do what you need. It is, however,
impossible to know this in general, since any optimization the
compiler can make can, at least in theory, be made by the CPU.
In practice, you may know what optimizations the hardware and the
compiler are capable of making. But relying on that knowledge tends to
produce very fragile code that fails when a new CPU comes out, when
it's compiled with a smarter processor, or that is very difficult to
port.
With the exception of the "terminate flag" application and those
defined by the C/C++ standards, use of 'volatile' should be considered
only as part of platform-specific optimizations.
DS
.
- Follow-Ups:
- Re: Newbie question: accessing global variable on multiprocessor
- From: Chris Thomasson
- Re: Newbie question: accessing global variable on multiprocessor
- References:
- Re: Newbie question: accessing global variable on multiprocessor
- From: Logan Shaw
- Re: Newbie question: accessing global variable on multiprocessor
- From: John Dallman
- Re: Newbie question: accessing global variable on multiprocessor
- From: Greg Herlihy
- Re: Newbie question: accessing global variable on multiprocessor
- From: Chris Thomasson
- Re: Newbie question: accessing global variable on multiprocessor
- From: Boris
- Re: Newbie question: accessing global variable on multiprocessor
- From: David Schwartz
- Re: Newbie question: accessing global variable on multiprocessor
- From: Boris
- Re: Newbie question: accessing global variable on multiprocessor
- From: David Schwartz
- Re: Newbie question: accessing global variable on multiprocessor
- From: Boris
- Re: Newbie question: accessing global variable on multiprocessor
- From: David Schwartz
- Re: Newbie question: accessing global variable on multiprocessor
- From: Boris
- Re: Newbie question: accessing global variable on multiprocessor
- From: David Schwartz
- Re: Newbie question: accessing global variable on multiprocessor
- From: Boris
- Re: Newbie question: accessing global variable on multiprocessor
- Prev by Date: Re: Linux pthreads real-time priority
- Next by Date: Re: Newbie question: accessing global variable on multiprocessor
- Previous by thread: Re: Newbie question: accessing global variable on multiprocessor
- Next by thread: Re: Newbie question: accessing global variable on multiprocessor
- Index(es):
Relevant Pages
|