public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* (no subject)
@ 2021-03-10 18:34 mscfd
  2021-03-11  7:48 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: mscfd @ 2021-03-10 18:34 UTC (permalink / raw)
  To: fortran

> which version of gfortran, and which operating system?
I have seen this on two different Linux distros on x86 with a recently compiled version, but also some time ago with an older gfortran 10 version.

Using helgrind on a simple omp do loop with write to a character variable, I get some possible data races in Libgfortran/io/unit.c. There a newunits array is allocated and possibly reallocated in "newunit_alloc". According to the lock outputs from helgrind I see that this routine is called even if output into character variable is done. Now "newunit_alloc" uses a lock to avoid having several thread all over the place. But newunit_free also writes to newunits array. And this routine does not obtain a lock itself (see comment in unit.c) So in theory it can happen that newunit_alloc reallocated newunits, and newunit_free writes to it just at this time. As I also use 18 threads the initial size of 16 does not suffice and reallocation does probably indeed happen.
Also acces to newunit_lwi is not protected as well (and complained about by helgrind).
 
Could it be that the corresponding write routine in transfer.c which calls newunit_free does not obtain the necessary lock. I cannot find it (which does not count much).
 
Any thoughts?
Martin

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re:
  2021-03-10 18:34 mscfd
@ 2021-03-11  7:48 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-03-11  7:48 UTC (permalink / raw)
  To: mscfd; +Cc: fortran

On Wed, Mar 10, 2021 at 8:39 PM mscfd via Fortran <fortran@gcc.gnu.org> wrote:
>
> > which version of gfortran, and which operating system?
> I have seen this on two different Linux distros on x86 with a recently compiled version, but also some time ago with an older gfortran 10 version.
>
> Using helgrind on a simple omp do loop with write to a character variable, I get some possible data races in Libgfortran/io/unit.c. There a newunits array is allocated and possibly reallocated in "newunit_alloc". According to the lock outputs from helgrind I see that this routine is called even if output into character variable is done. Now "newunit_alloc" uses a lock to avoid having several thread all over the place. But newunit_free also writes to newunits array. And this routine does not obtain a lock itself (see comment in unit.c) So in theory it can happen that newunit_alloc reallocated newunits, and newunit_free writes to it just at this time. As I also use 18 threads the initial size of 16 does not suffice and reallocation does probably indeed happen.
> Also acces to newunit_lwi is not protected as well (and complained about by helgrind).
>
> Could it be that the corresponding write routine in transfer.c which calls newunit_free does not obtain the necessary lock. I cannot find it (which does not count much).
>
> Any thoughts?

try obtaining the locks around the places you figured and see if your
problem goes away?

> Martin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-11  7:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 18:34 mscfd
2021-03-11  7:48 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).