https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90230

            Bug ID: 90230
           Summary: newunit in open function is not threadsafe with openmp
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mweiland at freenet dot de
  Target Milestone: ---

Created attachment 46239
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46239&action=edit
Source file to reproduce the error

The issue can be reproduced with:
gfortran -c -fopenmp minimal.f90
gfortran -fopenmp minimal.o
./a.out

It yields:
 opened file with lun:         -10
At line 7 of file minimal.f90
Fortran runtime error: File already opened in another unit


It seems to me that the newunit feature of open() is not threadsafe.
I get the output:
 opened file with lun:         -11
At line 7 of file minimal.f90
Fortran runtime error: File already opened in another unit

Error termination. Backtrace: 
...

With ifort/14.0 and NagCompiler, this example works, e.g.:
 ifort -c -fopenmp minimal.f90
 ifort -fopenmp minimal.o
./a.out
 opened file with lun:        -130
 closed file with lun:        -130
 opened file with lun:        -133
 opened file with lun:        -131
 opened file with lun:        -134
 opened file with lun:        -135
 closed file with lun:        -134
 opened file with lun:        -129
 closed file with lun:        -133
 closed file with lun:        -131
 closed file with lun:        -129
 opened file with lun:        -132
 closed file with lun:        -132
 opened file with lun:        -136
 opened file with lun:        -137
 closed file with lun:        -137
 closed file with lun:        -135
 opened file with lun:        -138
 closed file with lun:        -138
 closed file with lun:        -136


Not sure if this is really a bug, since I do not know if newunit is actually
supposed to be treadsafe from the Fortran standard.

Reply via email to