From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 43E033858D33; Wed, 10 Mar 2021 21:30:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43E033858D33 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/99529] libgfortran I/O: Data races related to new unit / new unit calls for I/O to strings Date: Wed, 10 Mar 2021 21:30:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Mar 2021 21:30:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99529 --- Comment #1 from Tobias Burnus --- Regarding calling newunit_alloc, that's due to libgfortran/io/unit.c's: get_unit (st_parameter_dt *dtp, int do_create) { gfc_unit *unit; if ((dtp->common.flags & IOPARM_DT_HAS_INTERNAL_UNIT) !=3D 0) { int kind; if (dtp->common.unit =3D=3D GFC_INTERNAL_UNIT) kind =3D 1; else if (dtp->common.unit =3D=3D GFC_INTERNAL_UNIT4) kind =3D 4; else internal_error (&dtp->common, "get_unit(): Bad internal unit KIND"); dtp->u.p.unit_is_internal =3D 1; dtp->common.unit =3D newunit_alloc (); unit =3D get_gfc_unit (dtp->common.unit, do_create); set_internal_unit (dtp, unit, kind); fbuf_init (unit, 128); return unit; } * * * >>From reading the report & looking at the code superficially, it seems as if= a patch is needed like: diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 27bee9d4e01..a6f115d5803 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -4360,3 +4360,5 @@ st_read_done_worker (st_parameter_dt *dtp) } + LOCK (&unit_lock); newunit_free (dtp->common.unit); + UNLOCK (&unit_lock); } @@ -4448,3 +4450,5 @@ st_write_done_worker (st_parameter_dt *dtp) } + LOCK (&unit_lock); newunit_free (dtp->common.unit); + UNLOCK (&unit_lock); }=