Am 29.09.2017 um 10:03 schrieb Janne Blomqvist:
1) I'm confused why fbuf_destroy is modified. The fbuf structure is
part of gfc_unit, and should be accessed with the same locking rules
as the rest of the gfc_unit components. When closing the unit, I think
the same should apply here, no?
It is to avoid a data race for
program main
use omp_lib
!$OMP PARALLEL NUM_THREADS(2)
call file_open(OMP_get_thread_num())
!$OMP END PARALLEL
contains
recursive subroutine file_open(i)
integer :: i
integer :: nunit
nunit = i + 20
write (nunit,*) 'asdf'
end subroutine file_open
end program main
which leads to
Read of size 4 at 0x7b580000ff30 by main thread (mutexes: write M16):
#0 close_unit_1 ../../../trunk/libgfortran/io/unit.c:699
(libgfortran.so.5+0x000000283ba6)
#1 _gfortrani_close_units ../../../trunk/libgfortran/io/unit.c:767
(libgfortran.so.5+0x000000283f59)
#2 cleanup ../../../trunk/libgfortran/runtime/main.c:113
(libgfortran.so.5+0x00000001fe22)
#3 _dl_fini <null> (ld-linux-x86-64.so.2+0x00000000fb62)
Previous write of size 4 at 0x7b580000ff30 by thread T1 (mutexes:
write M17):
#0 finalize_transfer ../../../trunk/libgfortran/io/transfer.c:3934
(libgfortran.so.5+0x000000281aa1)
#1 _gfortran_st_write_done
../../../trunk/libgfortran/io/transfer.c:4125
(libgfortran.so.5+0x000000281e35)
#2 file_open.3528 <null> (a.out+0x000000400c1b)
#3 MAIN__._omp_fn.0 <null> (a.out+0x000000400d27)
#4 gomp_thread_start ../../../trunk/libgomp/team.c:120
(libgomp.so.1+0x00000001756f)
Note that not all problems with implicit close at the end are resolved
so far, but that is a different problem.
2) I think the mutex init stuff can remain in insert_unit, just the
locking needs to move out and below freeing unit_lock like you have
done.
I can change that one easily.
Any other comments?
Regards
Thomas