https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92836
--- Comment #2 from Andrew Benson <abensonca at gmail dot com> --- Answers to questions raised by Jerry at: https://gcc.gnu.org/ml/fortran/2019-12/msg00059.html > 1) Are you opening a unique file (by file name) in each thread? No. The code is operating on many files, but in the specific case that causes the problem it's a file which is shared by all threads. Specifically, it's a file which is generated by the code if the file does not already exist (it stores solutions to a time-consuming calculation), or is read by the code if it does exist. All threads write/read the same file. > 2) Are you trying to synchronize these threads using the inquire? No. The inquire() is used only to see if the file exists already. If it does, the code branches to read the file, if it does not, the code branches to generate the data for the file and then write it. Synchronization of the file accesses are being handled using file locks, i.e. I use ISO_C_Binding to allow me to call fcntl(). Since the Linux kernel on the machine I'm using is too old to support OFD locks I'm using POSIX locks plus OpenMP locks (since POSIX locks are per processes so I have to separately synchronize the OpenMP threads). > 3) or, trying to ensure a unique filename for each file or avoid the same > file in two or more threads? No. The problem always seems to occur when a thread inquires() on one particular file, and the file name is the same across all threads. There are other places in my code where inquire() is being used on other file names. But in all cases the filename is the same for all threads.