On Fri, Jan 31, 2020 at 3:38 PM Janne Blomqvist <blomqvist.ja...@gmail.com> wrote: > > 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?
And, I forgot the ChangeLog entry. Here it is: libgfortran/ChangeLog: 2020-01-31 Janne Blomqvist <j...@gcc.gnu.org> PR libfortran/92836 * io/close.c (st_close): Close unit with unit_lock held. * io/io.h (gfc_unit): Remove waiting and closed members. (find_unit_locked): New prototype. (inc_waiting_locked): Remove. (predec_waiting_locked): Remove. (dec_waiting_unlocked): Remove. * io/list_read.c (nml_query): Avoid deadlock due to lock inversion. * io/unit.c (newunit_lock): New variable. (get_gfc_unit): Add new argument, use it. Remove logic waiting for closing logic.. (find_unit): Use new argument for get_gfc_unit. (find_unit_locked): New function. (find_or_create_unit): Use new argumet for gfc_get_unit. (get_unit): Likewise. (init_units): Initialize newunit_lock. (close_unit_1): Change meaning of locked argument, remove waiting for closing logic. (close_unit): Adapt to new close_unit_1 arguments. (close_units): Likewwise. (newunit_alloc): Use newunit_lock to protect. (newunit_free): Likewise. * io/unix.c (find_file0): Lock unit before accessing. (find_file): Remove waiting for closing logic. (flush_all_units_1): Likewise. (flush_all_units): Likewise. -- Janne Blomqvist