public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgomp/52303] New: libgomp leaves threads lying around that cause trouble if the program is later fork()'d
@ 2012-02-18  0:34 sdh4 at iastate dot edu
  2012-02-18 10:05 ` [Bug libgomp/52303] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sdh4 at iastate dot edu @ 2012-02-18  0:34 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52303
           Summary: libgomp leaves threads lying around that cause trouble
                    if the program is later fork()'d
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sdh4@iastate.edu


Libgomp creates a thread pool on each thread with a parallel section. This pool
silently hangs around even when no longer in the parallel section. 

If the process is later fork()'d and the child process subsequently enters a
parallel section, the child process will deadlock waiting on threads that do
not exist (fork() does not duplicate threads). 

The pthreads library provides a mechanism to avoid problems such as this.
Specifically (quoting the manpage for pthread_atfork()): 
       The  pthread_atfork() function provides multi-threaded libraries with a
       means to protect themselves from  innocent  application  programs  that
       call fork(), and it provides multi-threaded application programs with a
       standard mechanism for protecting themselves from  fork()  calls  in  a
       library routine or the application itself.

libgomp should call pthread_atfork() with team.c/gomp_free_thread() (or a
wrapper) as the "prepare" parameter so as to destroy the threadpool before
fork() is executed. 

The problem can be worked around by placing the parallel section in a
sub-thread that exits before fork() is called. libgomp automatically destroys
the thread-pool of a thread that exits.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-09-05 10:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-18  0:34 [Bug libgomp/52303] New: libgomp leaves threads lying around that cause trouble if the program is later fork()'d sdh4 at iastate dot edu
2012-02-18 10:05 ` [Bug libgomp/52303] " jakub at gcc dot gnu.org
2012-02-18 23:19 ` sdh4 at iastate dot edu
2012-02-19 18:50 ` jakub at gcc dot gnu.org
2013-09-05  9:47 ` olivier.grisel at ensta dot org
2013-09-05 10:06 ` olivier.grisel at ensta dot org

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).