Hi Janne,
Simplify IO locking in libgfortran. The new IO implementation avoids
accessing units without locks, as seen in PR 92836. It also avoids
lock inversion (except for a corner case wrt namelist query when
reading from stdin and outputting to stdout), making it easier to
verify correctness with tools like valgrind or threadsanitizer. It is
also simplified as the waiting and closed variables are not needed
anymore, making it easier to understand and analyze.
Regtested on x86_64-pc-linux-gnu, Ok for master?
Sorry it took me so long to actually look at this. The patch for
PR 93599 took a bit longer than anticipated...
With your patch on top of the one I just submitted, I get
valgrind errors for the asynchronous I/O tests:
$ gfortran -g async_io_1.f90 -pthread
$ valgrind --tool=drd ./a.out
==22685== drd, a thread error detector
==22685== Copyright (C) 2006-2017, and GNU GPL'd, by Bart Van Assche.
==22685== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==22685== Command: ./a.out
==22685==
==22685== Destroying locked mutex: mutex 0x60708f0, recursion count 1,
owner 1.
==22685== at 0x4C37B65: pthread_mutex_destroy_intercept
(drd_pthread_intercepts.c:865)
==22685== by 0x4C37B65: pthread_mutex_destroy
(drd_pthread_intercepts.c:875)
==22685== by 0x50A6CAE: __gthread_mutex_destroy (gthr-default.h:740)
==22685== by 0x50A6CAE: destroy_unit_mutex (unit.c:253)
==22685== by 0x50A6CAE: close_unit_1 (unit.c:732)
==22685== by 0x5091E67: _gfortran_st_close (close.c:108)
==22685== by 0x4011D3: MAIN__ (async_io_1.f90:25)
==22685== by 0x401AA9: main (async_io_1.f90:48)
==22685== mutex 0x60708f0 was first observed at:
==22685== at 0x4C37FD5: pthread_mutex_lock_intercept
(drd_pthread_intercepts.c:885)
==22685== by 0x4C37FD5: pthread_mutex_lock (drd_pthread_intercepts.c:898)
==22685== by 0x50A6039: __gthread_mutex_lock (gthr-default.h:749)
==22685== by 0x50A6039: insert_unit (unit.c:241)
==22685== by 0x50A615F: get_gfc_unit (unit.c:353)
==22685== by 0x509DC93: _gfortran_st_open (open.c:889)
==22685== by 0x400E4A: MAIN__ (async_io_1.f90:16)
==22685== by 0x401AA9: main (async_io_1.f90:48)
(plus a few more). I am currently bootstrapping without the patch
above so I can be sure that this is not an artifact.
However, it looks as if the "locked" argument to close_unit_1 gets
passed the wrong value somehow. Could you maybe look at that?
Regards
Thomas