Guys,
If I have a global variable, that is shared across multiple
threads on an SMP environment, then do I need to declare it as
volatile, so that a particular processor does not store and access its
vlaue fron the processor registers ?
Strange though it seems, this isn't a question about C.
Yes, you're asking about a C keyword and its effect on the
way a C program executes, but it's still not a C question.
The reason is that C's view of the way a program executes
is almost entirely single-threaded. There are a few hints --
volatile, signals -- that other agencies than "the" program
might be at work, but this part of the picture is blurry and
indistinct. C describes the effects of function calls, for
loops, if statements, and so on in terms of a single thread
of execution. The possibility of other threads isn't ruled
out altogether, but there's not enough information about how
they might work to be able to infer much about how they might
interact with each other.
... and in fact, different systems have different ways of
supporting asynchronous activities, leading to different ways
in which separate activities interact and coordinate. They
may start with C, but they build upon it in different -- and
not entirely compatible -- ways. And your question, phrased
in terms of a C keyword, is really about those beyond-C matters.
<off-topic>
To learn more about the "thread" model of asynchronous
execution, you may want to read comp.programming.threads for
a while. Among other things, you will learn that the volatile
keyword is neither necessary nor sufficient for sharing data
between multiple threads of execution; it's just irrelevant.
</off-topic>