From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.bugs Subject: bug#18222: 24.3.92; fork handlers in gmalloc.c can lead to deadlock Date: Sat, 09 Aug 2014 16:44:50 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: <53E4CC0B.2060200@cornell.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1407570324 533 80.91.229.3 (9 Aug 2014 07:45:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 9 Aug 2014 07:45:24 +0000 (UTC) Cc: 18222@debbugs.gnu.org To: Ken Brown Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 09 09:45:19 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XG1L4-00015D-1l for geb-bug-gnu-emacs@m.gmane.org; Sat, 09 Aug 2014 09:45:18 +0200 Original-Received: from localhost ([::1]:54427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XG1L3-00035A-LT for geb-bug-gnu-emacs@m.gmane.org; Sat, 09 Aug 2014 03:45:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XG1Kv-0002zw-9T for bug-gnu-emacs@gnu.org; Sat, 09 Aug 2014 03:45:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XG1Kq-0001fX-MV for bug-gnu-emacs@gnu.org; Sat, 09 Aug 2014 03:45:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:57320) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XG1Kq-0001f8-IL for bug-gnu-emacs@gnu.org; Sat, 09 Aug 2014 03:45:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XG1Kp-0006So-R6 for bug-gnu-emacs@gnu.org; Sat, 09 Aug 2014 03:45:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: YAMAMOTO Mitsuharu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Aug 2014 07:45:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18222 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 18222-submit@debbugs.gnu.org id=B18222.140757030024813 (code B ref 18222); Sat, 09 Aug 2014 07:45:03 +0000 Original-Received: (at 18222) by debbugs.gnu.org; 9 Aug 2014 07:45:00 +0000 Original-Received: from localhost ([127.0.0.1]:36029 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XG1Kl-0006S8-1d for submit@debbugs.gnu.org; Sat, 09 Aug 2014 03:44:59 -0400 Original-Received: from mathmail.math.s.chiba-u.ac.jp ([133.82.132.2]:58819) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XG1Kg-0006Ri-7V for 18222@debbugs.gnu.org; Sat, 09 Aug 2014 03:44:56 -0400 Original-Received: from fermat.math.s.chiba-u.ac.jp (fermat [133.82.132.10]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id 2625EC0562; Sat, 9 Aug 2014 16:44:50 +0900 (JST) In-Reply-To: <53E4CC0B.2060200@cornell.edu> User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (=?UTF-8?Q?Shij=C5=8D?=) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:92320 Archived-At: >>>>> On Fri, 08 Aug 2014 09:09:31 -0400, Ken Brown said: > malloc_enable_thread() in gmalloc.c calls pthread_atfork to set up fork > handlers. There are a couple of problems with this, but the immediate > reason for this bug report is a problem on Cygwin that was reported in > the thread starting at > https://cygwin.com/ml/cygwin/2014-07/msg00387.html > and continuing at > https://cygwin.com/ml/cygwin/2014-08/msg00001.html. > The issue is that the 'prepare' fork handler locks the pthread_mutexes > prior to forking, and the ensuing processing of the fork command by the > Cygwin DLL leads to a call to malloc in the same thread, resulting in > deadlock. This is a long-standing problem, but it was masked until > recently by the fact that pthread_mutexes on Cygwin were ERRORCHECK > mutexes by default. As of Cygwin 1.7.31, pthread_mutexes are now NORMAL > mutexes by default, so the problem has shown up. > A simple short-term workaround would be to explicitly set the mutexes to > be ERRORCHECK or RECURSIVE mutexes on Cygwin, thereby restoring the > previous behavior. But this does not seem like the right long-term > solution, for the reasons explained here: > https://cygwin.com/ml/cygwin/2014-08/msg00161.html > https://cygwin.com/ml/cygwin/2014-08/msg00175.html > I know nothing about this other than what I learned from the two > messages above, so I would appreciate some guidance. Originally, gmalloc.c bundled with Emacs was not thread-safe, so I added some mutex code as a short-term solution: http://lists.gnu.org/archive/html/emacs-devel/2007-06/msg01782.html Thread-safe malloc was required mainly for GLib (via GTK+, for example), and atfork handers were necessary because the threads internally used by GLib were not under our control. All the platforms I'm currently working at use their system malloc rather than Emacs's gmalloc.c, so I don't think I can be of much help about this issue. If changing mutex attributes works well, then I think that would be good enough for a workaround for upcoming 24.4 release. For a long term solution, it might be better to think about a transition to Cygwin's malloc (you mentioned malloc_set_state/malloc_get_state in (*), but they are used only when DOUG_LEA_MALLOC is defined). *: https://cygwin.com/ml/cygwin/2014-08/msg00167.html YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp