This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/51591] Strange output from STOP statement in OpenMP region
- From: "jb at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 17 Dec 2011 11:27:40 +0000
- Subject: [Bug fortran/51591] Strange output from STOP statement in OpenMP region
- Auto-submitted: auto-generated
- References: <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?