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

--- Comment #19 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to Xi Ruoyao from comment #18)
> I get warnings like below after building both libgomp and the test program
> with tsan (following PR55561 comment 15):
> 
> WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock)
> (pid=867077)
>   Cycle in lock order graph: M0 (0x7ffff0061550) => M1 (0x7fffebb270e0) => M0

This actually seems to be fine:

static gfc_unit *
get_gfc_unit (int n, int do_create)
{   
...
  RDLOCK (&unit_rwlock);
...
  RD_TO_WRLOCK (&unit_rwlock);
...
      p = insert_unit (n);
...
      RWUNLOCK (&unit_rwlock);
}

and

static gfc_unit *
insert_unit (int n)
{ 
  gfc_unit *u = xcalloc (1, sizeof (gfc_unit));
...
  LOCK (&u->lock);
...
  return u;
} 


Namely: The outer lock of get_gfc_unit locks the unit handling to create a new
unit – and the inner one creates one and returns in the locked state.
Then the outer one unlocks the generic unit handling - while the actual unit
remains locked.

Reply via email to