Hello world, as you can see from the PR, async_io_4.f90 exhibited a race condition every few thousands to tens of thousands of cases. This was difficult to track down, and took some thinking, discussion with Nicolas and enabling of the debugging feature of the async I/O, which finally produced a failure which could then be analyzed. The solution was to remove the mutexes for the different conditions that can happen in the async library, relying on the lock that protects the async I/O queue instead. Tested by Bill Seurer (thanks!) with a previous version of the patch, and with valgrind --tool=helgrind and valgrind --tool=drd, both of which showed no (new) failures for all of the async_io_*.f90 tests. So, OK for trunk and gcc-9? Regards Thomas 2020-02-17 Thomas Koenig PR fortran/93599 * io/async.c (destroy_adv_cond): Do not destroy lock. (async_io): Make sure au->lock is locked for finishing of thread. Do not lock/unlock around signalling emptysignal. Unlock au->lock before return. (init_adv_cond): Do not initialize lock. (enqueue_transfer): Unlock after signal. (enqueue_done_id): Likewise. (enqueue_done): Likewise. (enqueue_close): Likewise. (enqueue_data_transfer): Likewise. (async_wait_id): Do not lock/unlock around signalling au->work. (async_wait): Unlock after signal. * io/async.h (SIGNAL): Add comment about needed au->lock. Remove locking/unlocking of advcond->lock. (WAIT_SIGNAL_MUTEX): Add comment. Remove locking/unlocking of advcond->lock. Unlock mutex only at the end. Loop on __ghread_cond_wait returning zero. (REVOKE_SIGNAL): Add comment. Remove locking/unlocking of advcond->lock. (struct adv_cond): Remove mutex from struct.