24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Language</strong> <strong>Reference</strong><br />

2.82 VOLATILE Statement<br />

<br />

VOLATILE [a [,a] ...]<br />

where:<br />

a<br />

is a variable name or an array name.<br />

The VOLATILE statement is used to indicate that a variable or an element of an array may be updated<br />

concurrently by other code. A volatile variable or array element will not be cached (in a register) by the<br />

code generator. Each time a volatile variable or array element is referenced, it is loaded from memory.<br />

Each time a volatile variable or array element is updated, it is stored back into memory.<br />

Notes:<br />

1. A name cannot appear in a VOLATILE statement more than once in the same program unit.<br />

2. Dummy arguments, procedure names, and common block names are not permitted in a<br />

VOLATILE statement.<br />

In the following example, the subroutine A_THREAD waits on the HoldThreads semaphore. It uses the<br />

VOLATILE statement to ensure that the variable is re-loaded from memory each time through the loop.<br />

Example:<br />

SUBROUTINE A_THREAD()<br />

STRUCTURE /RTL_CRITICAL_SECTION/<br />

INTEGER*4 DebugInfo<br />

INTEGER*4 LockCount<br />

INTEGER*4 RecursionCount<br />

INTEGER*4 OwningThread<br />

INTEGER*4 LockSemaphore<br />

INTEGER*4 Reserved<br />

END STRUCTURE<br />

INTEGER NumThreads<br />

LOGICAL HoldThreads<br />

VOLATILE HoldThreads<br />

RECORD /RTL_CRITICAL_SECTION/ CriticalSection<br />

COMMON NumThreads, HoldThreads, CriticalSection<br />

INTEGER threadid<br />

WHILE( HoldThreads )DO<br />

CALL Sleep( 1 )<br />

END WHILE<br />

PRINT ’(’’Hi from thread ’’, i4)’, threadid()<br />

CALL EnterCriticalSection( CriticalSection )<br />

NumThreads = NumThreads - 1<br />

CALL LeaveCriticalSection( CriticalSection )<br />

CALL endthread()<br />

END<br />

144 VOLATILE Statement

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!