https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92836
--- Comment #4 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> --- Removing close statement: $ ./a.out 0 8 4 2 8 4 -10 5 8 4 4 8 4 3 8 4 At line 16 of file bug1.f90 Fortran runtime error: End of record 6 8 4 At line 14 of file bug1.f90 Internal Error: Unit number changed At line 14 of file bug1.f90 What I speculate is happening is that newunit is getting invoked in the middle of trying to close the unit on a different thread and we do end up with duplicate unit numbers assigned by newunit. I need to look at that code yet. Exploring further here.