https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119136

--- Comment #23 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
What I meant is basically contained in https://man.cx/pthread_mutex_lock(3)
gthr*.h currently provides two kinds of mutexes, the normal one as
__gthread_mutex_t
and __GTHREAD_MUTEX_INIT/__GTHREAD_MUTEX_INIT_FUNCTION and
__gthread_mutex_{destroy,lock,unlock,trylock,timedlock} APIs, and then the
recursive
mutex as __gthread_recursive_mutex_t, __GTHREAD_RECURSIVE_* and
__gthread_recursive_mutex*.
One could add __gthread_errorchecking_mutex_t etc. similarly, map that to the
same pthread_mutex_* typedef/APIs except for
__GTHREAD_ERRORCHECKING_MUTEX_INIT{,_FUNCTION}
and use that in libgfortran for the lock variable (leave others as is).
What makes it more complicated is whether something similar is achievable for
Win32, VxWorks, RTEMS, etc., whatever provides gthr.h.
So, you could also do it in an incremental way, only add the new stuff to
gthr-posix.h for now and use it in libgfortran only conditionally.
Or don't add new __gthread_*mutex_t typedef and just define
__GTHREAD_ERRORCHECKING_MUTEX_INIT{,_FUNCTION} and nothing else and only change
insert_unit's
#ifdef __GTHREAD_MUTEX_INIT
  {
    __gthread_mutex_t tmp = __GTHREAD_MUTEX_INIT;
    u->lock = tmp;
  }
#else
  __GTHREAD_MUTEX_INIT_FUNCTION (&u->lock);
#endif
to preferably use __GTHREAD_ERRORCHECKING_* over these if those are defined.
And if those are defined, tweak also
      LOCK (&p->lock);
in get_gfc_unit if those are defined to test if LOCK didn't return EDEADLK and
in that case somehow signal to the caller that it should emit the error (or
emit it itself).

Reply via email to