Everything2
Near Matches
Ignore Exact
Full Text
Everything2

Volatile

created by BaronCarlos

(idea) by zodiac (4.1 y) (print)   ?   I like it! Wed Apr 12 2000 at 15:47:44

a C-keyword.
denotes that the content of the pointer should not be cached (e.g. held in a register) but always written through, which is important if you do memory mapped I/O.

(idea) by xriso (2.3 y) (print)   ?   I like it! Fri May 03 2002 at 8:47:27

volatile is a rarely-used and little understood keyword in the C programming language. Here is my best information on what exactly it means.

When you tell the compiler that you want a variable to be volatile, this basically tells it to not do any really fancy optimisations. This means that the compiler has to make sure that at the end of every statement, all side-effects pertaining to volatile memory have be in effect. The best example that comes to mind is this:

int my_int;
my_int = 5;
...
/* Some more statements */
...
my_int++;

What is the state of my_int's actual memory between my_int = 5 and my_int++? Well, since we haven't declared my_int as a volatile, this is undefined. The compiler may just put my_int into a register and then operate on that, and only after my_int++ will it update the memory value. All references to my_int would just refer to the register.

If we instead say

volatile int my_int;
my_int = 5;
...
/* Some more statements */
...
my_int++;
then between my_int = 5 and my_int++ we know that the memory for my_int is equal to 5.

Usually this is no big deal to the programmer. The compiler can do whatever it wants in the machine language as long as in the end, it performs correctly. However, there are certain times when you want to make sure that the memory is accurate between statements.

  • Shared memory. You have a piece of code that changes some memory shared between two different processes. You want to make sure that the memory really is updated by the time the other process reads it.
  • Memory mapping. This is a form of shared memory. It is alright to optimise your memory accesses while the file is open, but when you unmap the file you really want to make sure that all your changes are properly recorded.
  • Threaded programming. In most threaded programs, there will be some communication between processes. This is usually through the memory that the threads share together, since it is a fast method. See above for why shared memory often needs volatile.

(definition) by Webster 1913 (print) I like it! Wed Dec 22 1999 at 4:18:38

Vol"a*tile (?), a. [F. volatil, L. volatilis, fr. volare to fly, perhaps akin to velox swift, E. velocity. Cf. Volley.]

1.

Passing through the air on wings, or by the buoyant force of the atmosphere; flying; having the power to fly.

[Obs.]

2.

Capable of wasting away, or of easily passing into the aeriform state; subject to evaporation.

⇒ Substances which affect the smell with pungent or fragrant odors, as musk, hartshorn, and essential oils, are called volatile substances, because they waste away on exposure to the atmosphere. Alcohol and ether are called volatile liquids for a similar reason, and because they easily pass into the state of vapor on the application of heat. On the contrary, gold is a fixed substance, because it does not suffer waste, even when exposed to the heat of a furnace; and oils are called fixed when they do not evaporate on simple exposure to the atmosphere.

3.

Fig.: Light-hearted; easily affected by circumstances; airy; lively; hence, changeable; fickle; as, a volatile temper.

You are as giddy and volatile as ever. Swift.

Volatile alkali. Old Chem. See under Alkali. -- Volatile liniment, a liniment composed of sweet oil and ammonia, so called from the readiness with which the latter evaporates. -- Volatile oils. Chem. See Essential oils, under Essential.

 

© Webster 1913.


Vol"a*tile, n. [Cf. F. volatile.]

A winged animal; wild fowl; game.

[Obs.]

Chaucer. Sir T. Browne.

 

© Webster 1913.


printable version
chaos

memory mapped non-volatile memory C keywords Human Relations Test
Funny C declarations the optimizer is your friend register Black Label Society
auto secularism is not atheism Java keywords Evolatic
How many chickens? A rose by any other name would smell as sweet Aisha Clan Clan Hydrogen peroxide
Chervil snow line Futurist Reconstruction of the Universe Huygens probe
const Swap Jovian planets FPGA
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
What you are reading:
September 11, 2001 - II
Watching "a long good-bye," caring for an Alzheimer's patient
Hausdorff dimension
Obedience to Authority
Theodore Roethke
The Rime of the Ancient Mariner
When Democracy Failed: The warnings of history
Do you take it I would astonish? Does the daylight astonish?
aburage
Contemporary Christian music
nectarine
How to peel and devein shrimp
There is magic in this world
New Writeups
SteveMurrayFromNZ
Waiver(idea)
nailbiter
nerve stapling(thing)
locke baron
Multiple Myeloma(thing)
SubSane
blonde, freckles, skinny, short(person)
arcanamundi
A Ruba'iyat for May(person)
riverrun
Timed Writing(idea)
auraseer
Fling(fiction)
StrawberryFrog
Iron Man(review)
devolution
Misogyny and Porn, East to West - An Empirical Analysis(idea)
devolution
Korea is a place that refuses to stand still(idea)
Beanie127
The Pacifist Soldier(fiction)
VergilKint
Distilled from Dreams(fiction)
Scaevola
Roman marriage(thing)
rootbeer277
m&m's Ice Cream Treats(review)
Transitional Man
Gus's Chalet(review)
E2 is a by-product of the existence of The Everything Development Company