public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jb at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-51591-4-e3yykcwJGH@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-51591-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51591

--- Comment #2 from Janne Blomqvist <jb at gcc dot gnu.org> 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?


  parent reply	other threads:[~2011-12-17 11:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 22:31 [Bug fortran/51591] New: " longb at cray dot com
2011-12-17 10:21 ` [Bug fortran/51591] " burnus at gcc dot gnu.org
2011-12-17 11:32 ` jb at gcc dot gnu.org [this message]
2012-02-03 22:09 ` bdavis at gcc dot gnu.org
2013-05-11 17:09 ` bdavis at gcc dot gnu.org
2015-10-20 14:54 ` dominiq at lps dot ens.fr
2020-07-30 15:17 ` dominiq at lps dot ens.fr
2020-07-30 15:23 ` jakub at gcc dot gnu.org

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=bug-51591-4-e3yykcwJGH@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).