On 10/01/17 15:41, Thomas Koenig wrote: > Am 01.10.2017 um 10:59 schrieb Bernd Edlinger: >> maybe there is a way how you could explicitly join >> all running threads? > > Yes, that seems to do the trick. Thanks! >
Oh, that is really very surprising... I believe that all omp threads are created in detached state, so pthread_join should be undefined on them, just tsan *thinks* otherwise? When I look further on the libgomp sources, I see there are two completely different implementations of the mutexes, barriers, etc. One using posix functions which should be visible to tsan and another one using raw linux futex calls which should be invisible to tsan, by default the linux system calls are used, which explains why tsan seems to be unaware of the actual synchronization in this example. Have you tried to build with --enable-linux-futex=no ? I just saw the following line in libgomp/configure.tgt: # Since we require POSIX threads, assume a POSIX system by default. config_path="posix" # Check for futex enabled all at once. if test x$enable_linux_futex = xyes; then So maybe completely different things will be reported if this value is set to no? > Here is a patch which appears to work. It does hit a snag with static > linking, though, because it calls __gthread_self (), and that causes > a segfault with -static :-(. > > The test case in question is static_linking_1.f. > > This appears to be a general problem, and has been discussed > before, for example in > https://gcc.gnu.org/ml/gcc-help/2010-05/msg00029.html . > > What would be the best way to proceed? Modify the behavior of -static > with gfortran? > > Regards > > Thomas > > 2017-10-01 Thomas Koenig <tkoe...@gcc.gnu.org> > > > PR fortran/66756 > PR fortran/82378 > * io/io.h: Add field th to gfc_unit. Add prototypes for > lock_unit and trylock_unit. > * io/unit.c (insert_unit): Do not create lock and lock, move to > (gfc_get_unit): here; lock after insert_unit has succeded. > Use lock_unit and trylock_unit instead of __gthread_mutex_lock > and __gthread_mutex_trylock. > (init_units): Do not unlock unit locks for stdin, stdout and > stderr. > (lock_unit): New function. > (trylock_unit): New function. > (close_units): If a unit still has a lock, wait for the > completion of the corresponding thread. > * io/unix.c (find_file): Use lock_unit and trylock_unit instead > of __gthread_mutex_lock and __gthread_mutex_trylock. > (flush_all_units): Likewise. > > 2017-10-01 Thomas Koenig <tkoe...@gcc.gnu.org> > > PR fortran/66756 > PR fortran/82378 > * gfortran.dg/openmp-close.f90: New test.