Depending on the value specified by the ACTION (or READONLY) specifier in the OPEN statement, the file will be opened by your program for reading, writing, or both reading and writing records. This simply checks that the program itself executes the type of statements intended.
File locking mechanisms allow users to enable or restrict access to a particular file when that file is being accessed by another process.
Intel® Fortran file locking features provide three file access modes:
Implicit Shared mode, which occurs when no mode is specified. This is also called No Locking.
Explicit Shared mode, when all cooperating processes have access to a file. This mode is set in the OPEN statement by the SHARED specifier or the SHARE='DENYNONE' specifier.
Exclusive mode, when only one process has access to a file. This mode is set in the OPEN statement by the NOSHARED specifier or the SHARE='DENYRW' specifier.
The file locking mechanism looks for explicit setting of the corresponding specifier in the OPEN statement. Otherwise, the Fortran run time does not perform any setting or checking for file locking and the process can access the file regardless of the fact that other processes have already opened or locked the file.
Example 1: Implicit Shared Mode (No Locking)
Process 1 opens the file without a specifier, resulting
in no locking.
Process 2 now tries to open the file:
It gains access regardless of the mode it is using.
Example 2: Explicit Shared Mode
Process 1 opens the file with Explicit Shared mode.
Process 2 now tries to open the file:
If process 2 opens the file with Explicit Shared mode or Implicit Shared (No Locking) mode, it gets access to the file.
If process 2 opens the
file with Exclusive mode, it receives an error.
Example 3: Exclusive Mode
Process 1 opens the file with Exclusive mode.
Process 2 now tries to open the file:
If process 2 opens the file with Implicit Shared (No Locking) mode, it gets access to the file.
If process 2 opens the
file with Explicit Shared or Exclusive mode, it receives an error.
The Fortran runtime does not coordinate file entry updates during cooperative access. The user needs to coordinate access times among cooperating processes to handle the possibility of simultaneous WRITE and REWRITE statements on the same record positions.