From: Janne Blomqvist <blomqvist.janne@gmail.com>
To: Thomas Koenig <tkoenig@netcologne.de>
Cc: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [patch, libfortran] Fix thead sanitizer issue with libgfortran
Date: Sun, 01 Oct 2017 07:42:00 -0000 [thread overview]
Message-ID: <CAO9iq9Ekmk+hUfAD04pVTVogdazm3tghruoyX_62uMJZhrQmmQ@mail.gmail.com> (raw)
In-Reply-To: <fa7466a3-3589-27b8-b924-1b0c35ee60f9@netcologne.de>
On Fri, Sep 29, 2017 at 9:53 PM, Thomas Koenig <tkoenig@netcologne.de> wrote:
> Am 29.09.2017 um 10:03 schrieb Janne Blomqvist:
>
>>
>> 1) I'm confused why fbuf_destroy is modified. The fbuf structure is
>> part of gfc_unit, and should be accessed with the same locking rules
>> as the rest of the gfc_unit components. When closing the unit, I think
>> the same should apply here, no?
>
>
> It is to avoid a data race for
>
> program main
> use omp_lib
> !$OMP PARALLEL NUM_THREADS(2)
> call file_open(OMP_get_thread_num())
> !$OMP END PARALLEL
> contains
> recursive subroutine file_open(i)
> integer :: i
> integer :: nunit
> nunit = i + 20
> write (nunit,*) 'asdf'
> end subroutine file_open
> end program main
>
> which leads to
>
> Read of size 4 at 0x7b580000ff30 by main thread (mutexes: write M16):
> #0 close_unit_1 ../../../trunk/libgfortran/io/unit.c:699
> (libgfortran.so.5+0x000000283ba6)
> #1 _gfortrani_close_units ../../../trunk/libgfortran/io/unit.c:767
> (libgfortran.so.5+0x000000283f59)
> #2 cleanup ../../../trunk/libgfortran/runtime/main.c:113
> (libgfortran.so.5+0x00000001fe22)
> #3 _dl_fini <null> (ld-linux-x86-64.so.2+0x00000000fb62)
>
> Previous write of size 4 at 0x7b580000ff30 by thread T1 (mutexes: write
> M17):
> #0 finalize_transfer ../../../trunk/libgfortran/io/transfer.c:3934
> (libgfortran.so.5+0x000000281aa1)
> #1 _gfortran_st_write_done ../../../trunk/libgfortran/io/transfer.c:4125
> (libgfortran.so.5+0x000000281e35)
> #2 file_open.3528 <null> (a.out+0x000000400c1b)
> #3 MAIN__._omp_fn.0 <null> (a.out+0x000000400d27)
> #4 gomp_thread_start ../../../trunk/libgomp/team.c:120
> (libgomp.so.1+0x00000001756f)
>
> Note that not all problems with implicit close at the end are resolved
> so far, but that is a different problem.
I'm still confused. If gfc_unit->fbuf needs to be protected by holding
gfc_unit->lock when closing, surely the same applies to other
gfc_units fields as well? How if gfc_unit->fbuf special? AFAICS it
isn't..
--
Janne Blomqvist
next prev parent reply other threads:[~2017-10-01 7:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-28 17:29 Thomas Koenig
2017-09-29 6:03 ` Thomas Koenig
2017-09-29 8:04 ` Janne Blomqvist
2017-09-29 18:53 ` Thomas Koenig
2017-10-01 7:42 ` Janne Blomqvist [this message]
2017-10-01 9:02 Bernd Edlinger
2017-10-01 13:41 ` Thomas Koenig
2017-10-01 14:23 ` Bernd Edlinger
2017-10-01 16:54 ` Thomas Koenig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAO9iq9Ekmk+hUfAD04pVTVogdazm3tghruoyX_62uMJZhrQmmQ@mail.gmail.com \
--to=blomqvist.janne@gmail.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=tkoenig@netcologne.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).