473,467 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

MSDN volatile sample

Hello everyone,
In the MSDN volatile sample,

http://msdn2.microsoft.com/en-us/lib...fd(VS.80).aspx

I do not understand what is the purpose of the sample. I have tried to
remove the keyword volatile, and the result is the same. :-)

Any ideas?
thanks in advance,
George
Dec 28 '07 #1
7 3212
On 2007-12-28 02:53:28 -0600, George2 <ge*************@yahoo.comsaid:
http://msdn2.microsoft.com/en-us/lib...fd(VS.80).aspx
Compile it with optimizations on (i.e. Release build).

-dr

Dec 29 '07 #2
On Dec 28, 12:53*am, George2 <george4acade...@yahoo.comwrote:
Hello everyone,

In the MSDN volatile sample,

http://msdn2.microsoft.com/en-us/lib...fd(VS.80).aspx

I do not understand what is the purpose of the sample. I have tried to
remove the keyword volatile, and the result is the same. :-)

Any ideas?

thanks in advance,
George
I would not rely on volatile for anything related to threads. Think of
it as more of a hint to the compiler when it's considering the
variable's scope (especially when optimizing).
Dec 29 '07 #3
On 2007-12-28 18:56:26 -0600, st**************@gmail.com said:
On Dec 28, 12:53*am, George2 <george4acade...@yahoo.comwrote:
>Hello everyone,

In the MSDN volatile sample,

http://msdn2.microsoft.com/en-us/lib...fd(VS.80).aspx

I do not understand what is the purpose of the sample. I have tried to
remove the keyword volatile, and the result is the same. :-)

Any ideas?

thanks in advance,
George

I would not rely on volatile for anything related to threads. Think of
it as more of a hint to the compiler when it's considering the
variable's scope (especially when optimizing).
I don't understand what you mean. volatile has nothing to do with scope
and everything to do with optimization.

Beyond its sequence-point properties, the behavior of volatile
variables is completely implementation-defined, which means that the
effect of the volatile qualifier is not portable in any meaningful,
externally-observable way.

Thus, I wouldn't use it for anything portable, period.

-dr

Dec 29 '07 #4
On Dec 28, 8:34*pm, Dave Rahardja
<drahardja.place...@sign.here.pobox.comwrote:
On 2007-12-28 18:56:26 -0600, steve.pagliar...@gmail.com said:


On Dec 28, 12:53*am, George2 <george4acade...@yahoo.comwrote:
Hello everyone,
In the MSDN volatile sample,
>http://msdn2.microsoft.com/en-us/lib...fd(VS.80).aspx
I do not understand what is the purpose of the sample. I have tried to
remove the keyword volatile, and the result is the same. :-)
Any ideas?
thanks in advance,
George
I would not rely on volatile for anything related to threads. Think of
it as more of a hint to the compiler when it's considering the
variable's scope (especially when optimizing).

I don't understand what you mean. volatile has nothing to do with scope
and everything to do with optimization.

Beyond its sequence-point properties, the behavior of volatile
variables is completely implementation-defined, which means that the
effect of the volatile qualifier is not portable in any meaningful,
externally-observable way.

Thus, I wouldn't use it for anything portable, period.

-dr- Hide quoted text -

- Show quoted text -
I believe we are in agreement. My use of scope was targeted to the
optimizer and not the language proper.
-Steve
Dec 29 '07 #5
[included comp.programming.threads]

"George2" <ge*************@yahoo.comwrote in message
news:dd**********************************@t1g2000p ra.googlegroups.com...
Hello everyone,
In the MSDN volatile sample,

http://msdn2.microsoft.com/en-us/lib...fd(VS.80).aspx

I do not understand what is the purpose of the sample. I have tried to
remove the keyword volatile, and the result is the same. :-)

Any ideas?
It means that MS compilers for PowerPC (e.g., XBOX), and Itanium (e.g.,
Itanic) based platforms do indeed assign significantly __overbearing!__
memory-barrier functionality to their most "basic" meaning of the volatile
keyword itself; by default! ;^(... Volatile is implementation defined
INDEED!

Basically, they assign heavy acquire-load membar semantics to EVERY _naked_
load, and release-store semantics to EVERY _naked_ store; this could be due
to their relationship with Intel I suppose. Keep in mind that Java does this
as well for programming "simplicity"; IMVHO, all of that crap is MAJOR
overkill and generates unneeded overheads on the memory coherency system in
general. Dumbs down things to a level that makes things ridiculous.

They certainly do NOT have any real need to define volatile such that it has
anything to do with shared-memory threading. IMO, using volatile and
threading in then same sentence is certainly misleading to say the least,
and usually winds up getting people to make erroneous assumptions about
C/C++ compilers...

;^(...

Jan 7 '08 #6
George2 <ge*************@yahoo.comwrites:
In the MSDN volatile sample,

http://msdn2.microsoft.com/en-us/lib...fd(VS.80).aspx

I do not understand what is the purpose of the sample. I have tried to
remove the keyword volatile, and the result is the same. :-)

Any ideas?
volatile means that given variable may change at any time and compiler
have no way of knowing that it may happen (no, it's not the definition
of volatile keyword but it helps understand it). Assume that compiler
knows that Sleep() function will never modify Sentinel -- in this case
a loop

while (Sentinel)
Sleep(0);

might be replaced with

if (Sentinel)
while (1)
Sleep(0);

if there would be no volatile keyword. That's because without volatile
keyword compiler could came to a conclusion that value of Sentinel does
not change in body of the loop so if the condition was true at the
beginning it will be true all the time.

With volatile keyword compiler must check Sentinel's value since it no
longer knows that it's value was not changed (that's basically meaning
of that keyword).

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
Jan 7 '08 #7
"James Kanze" <ja*********@gmail.comwrote in message
news:4d**********************************@e23g2000 prf.googlegroups.com...
[...]
Interesting. The problem is that unless I've misunderstood
something about the x86 architecture, this description doesn't
correspond to the code generated by VC++ 8.
This might be useful:

http://developer.intel.com/products/...als/318147.pdf

?

[...]

Jan 8 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: newsock | last post by:
Why need to qualify a member function "volatile"? Why need to qualify a object "volatile"? When need to "const_cast" away "volatile" of an object and a member function? I also saw some code...
8
by: Tim Rentsch | last post by:
Here's another question related to 'volatile'. Consider the following: int x; void foo(){ int y; y = (volatile int) x;
5
by: ben | last post by:
Hello All, I am trying to make sense of a bit of syntax, is there a guru out there that can clear this up for me. I have a buffer declared as static volatile u8 buffer; and I have a...
14
by: google-newsgroups | last post by:
Hello, even (or because?) reading the standard (ISO/IEC 9899/1999) I do not understand some issues with volatile. The background is embedded programming where data is exchanged between main...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
3
by: arun.darra | last post by:
Hi, Is the following thread safe?? class Sample { private: volatile int number; public: Sample():number(0) {}
3
by: Rakesh Kumar | last post by:
Hi - I am actually trying to get my feet in multi-threaded C++ programming. While I am aware that the C++ standard does not talk about threads (at least, for now - in C++03) - my question is more...
8
by: CJ | last post by:
The following tries to make thread-safe code while avoiding the high cost of a lock. But is it kosher? // file or global scope level int X; volatile _Bool IsInitializedX=false;
6
by: George2 | last post by:
Hello everyone, In the MSDN volatile sample, http://msdn2.microsoft.com/en-us/library/12a04hfd(VS.80).aspx I do not understand what is the purpose of the sample. I have tried to remove the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.