From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11759 invoked by alias); 18 Feb 2012 00:19:51 -0000 Received: (qmail 11742 invoked by uid 22791); 18 Feb 2012 00:19:48 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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, 18 Feb 2012 00:19:36 +0000 From: "sdh4 at iastate dot edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug libgomp/52303] New: libgomp leaves threads lying around that cause trouble if the program is later fork()'d Date: Sat, 18 Feb 2012 00:34:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libgomp X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sdh4 at iastate dot edu 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: 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: 2012-02/txt/msg01834.txt.bz2 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.