Volatile (computer programming): Difference between revisions

Content deleted Content added
m Duplicate word removed
Line 1:
{{Short description|A keyword used in some programming languages to tag variables}}
{{Lowercase title}}
In [[computer programming]], a '''volatile''' [[Value (computer science)|value]] is asaid value that canto be asynchronously'''''volatile''''' readif byit somethingcan elsebe read or modified asynchronously changed by something elseother whilethan the current code[[thread is(computing)|thread runningof execution]].
The value of a <code>volatile</code> variable may spontaneously change for reasons such as:
 
sharing values with other [[thread (computing)|threads of execution]];
Despite being a common keyword across many programming languages, the behavior of the <code>volatile</code> keyword differs in subtle and important ways between the several programming languages that have it. The common theme is that a <code>volatile</code> variable is a variable that may be read or modified by something outside of the current [[thread (computing)|thread of execution]] while the current [[thread (computing)|thread]] is running. In particular, the value of a <code>volatile</code> variable may spontaneously change without any possible cause from the code in the current [[thread (computing)|thread]], and sometimes a <code>volatile</code> variable may spontaneously change without any possible cause from any code in the whole program. The typical reasons to use <code>volatile</code> include: accessing hardware devices via [[memory-mapped I/O]] (where you can send and receive messages from [[peripheral device]]s by reading from and writing to memory), sharing values with asynchronous signal handlers, and sharing values with other [[thread (computing)|threads of execution]]. Support for these use cases varies considerably among the several programming language that have the <code>volatile</code> keyword.
sharing values with asynchronous [[signal handler]]s;
 
accessing hardware devices via [[memory-mapped I/O]] (where you can send and receive messages from [[peripheral device]]s by reading from and writing to memory).
Support for these use cases varies considerably among the several programming language that have the <code>volatile</code> keyword.
Volatility can have implications regarding function [[calling convention]]s and how variables are stored, accessed and cached.