From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3775 invoked by alias); 17 Dec 2011 11:28:23 -0000 Received: (qmail 3766 invoked by uid 22791); 17 Dec 2011 11:28:22 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BG X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 17 Dec 2011 11:28:10 +0000 From: "jb at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/51591] Strange output from STOP statement in OpenMP region Date: Sat, 17 Dec 2011 11:32:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: openmp X-Bugzilla-Severity: minor X-Bugzilla-Who: jb at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-12/txt/msg01918.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51591 --- Comment #2 from Janne Blomqvist 2011-12-17 11:27:40 UTC --- Looks like some kind of race condition.. E.g. what about: STOP calls exit(), which leads to the library destructor being called, which calls close_units(), which closes each open unit in the tree. But somehow the print statement from another thread also thinks it has access to the unit, and then tries to print something, which segfaults because the other thread is in the process of shutting down the same unit? Hmm, now that I quickly looked at the code, the above looks likely. So close_units() acquires unit_lock (the global lock protecting the unit tree), then closes each unit without acquiring the unit's own lock (u->lock). For comparison, in normal IO statements, first we acquire unit_lock, find the unit in the tree, acquire u->lock, then release unit_lock. Then do the IO with u->lock held, and finally relase u->lock. So it seems that it would be possible for the print statement to acquire the u->lock before the close_units gets to lock unit_lock, and thus we have a race? Of course, this is based on a very quick scan of the code, and I could be all wrong. Perhaps Jakub knows better, as he designed the libgfortran locking scheme?