Volatile (computer programming): Difference between revisions

Content deleted Content added
In Java: clarified the global ordering over volatiles
Line 234:
 
==In Fortran==
The <code>volatileVOLATILE</code> is part of the Fortran 2003 standard,<ref>{{cite web |url=http://docs.cray.com/books/S-3692-51/html-S-3692-51/zfixedn3c8sk4c.html|title=VOLATILE Attribute and Statement|publisher=Cray}}</ref> although earlier version supported it as an extension. Making all variables <code>volatile</code> in a function is also useful finding [[aliasing (computing)|aliasing]] related bugs.
<syntaxhighlight lang="fortran">
integer, volatile :: i ! When not defined volatile the following two lines of code are identical
Line 240:
write(*,*) i*i ! Loads the variable i twice from memory and multiplies those values
</syntaxhighlight>
 
By always "drilling down" to memory of a VOLATILE, the Fortran compiler is precluded from reordering reads or writes to volatiles. This makes visible to other threads actions done in this thread, and vice versa.<ref>{{cite web
|url=https://software.intel.com/en-us/forums/intel-moderncode-for-parallel-architectures/topic/279191
|title=Volatile and shared array in Fortran |website=Intel.com}}</ref>
 
Use of VOLATILE reduces and can even prevent optimization.<ref>{{cite web
|url=https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnbq/index.html
|title=VOLATILE |website=Oracle.com}}</ref>
 
==References==