unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
To: "Jan D." <jan.h.d@swipnet.se>
Cc: "Herbert J. Skuhra" <h.skuhra@gmail.com>, emacs-devel@gnu.org
Subject: Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
Date: Mon, 06 Aug 2007 17:47:55 +0900	[thread overview]
Message-ID: <wlhcnd59s4.wl%mituharu@math.s.chiba-u.ac.jp> (raw)
In-Reply-To: <46B0D07A.4010103@swipnet.se>

>>>>> On Wed, 01 Aug 2007 20:27:06 +0200, "Jan D." <jan.h.d@swipnet.se> said:

> I tried it and temacs runs OK.  However, it seems that the mutex 
> initialization is lost, so it has to be done again with the dumped
> emacs.  pthread_self also allocates memory, so even if this is fixed
> we still get a loop.

How about deferring mutex initializations until an interactive session
starts?  Could you try the patch below?

> I also tried using system malloc on FreeBSD 6.2, but that didn't
> work.  Emacs crashed on first realloc (heap corrupt).  I guess
> undumping on FreeBSD with system malloc is broken (or perhaps
> impossible).

Too bad...

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp

Index: src/emacs.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/emacs.c,v
retrieving revision 1.404
diff -c -p -r1.404 emacs.c
*** src/emacs.c	26 Jul 2007 05:27:51 -0000	1.404
--- src/emacs.c	6 Aug 2007 08:40:40 -0000
*************** main (argc, argv
*** 1164,1169 ****
--- 1164,1176 ----
        setpgrp ();
  #endif
  #endif
+ #if defined (HAVE_GTK_AND_PTHREAD) && !defined (SYSTEM_MALLOC) && !defined (DOUG_LEA_MALLOC)
+       {
+ 	extern void malloc_enable_thread P_ ((void));
+ 
+ 	malloc_enable_thread ();
+       }
+ #endif
      }
  
    init_signals ();
Index: src/gmalloc.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/gmalloc.c,v
retrieving revision 1.24
diff -c -p -r1.24 gmalloc.c
*** src/gmalloc.c	29 Jul 2007 10:12:21 -0000	1.24
--- src/gmalloc.c	6 Aug 2007 08:40:40 -0000
*************** extern __ptr_t memalign PP ((__malloc_si
*** 136,141 ****
--- 136,145 ----
  extern __ptr_t valloc PP ((__malloc_size_t __size));
  #endif
  
+ #ifdef USE_PTHREAD
+ /* Set up mutexes and make malloc etc. thread-safe.  */
+ extern void malloc_enable_thread PP ((void));
+ #endif
  
  #ifdef _MALLOC_INTERNAL
  
*************** extern void _free_internal_nolock PP ((_
*** 242,249 ****
  
  #ifdef USE_PTHREAD
  extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
! #define LOCK()     pthread_mutex_lock (&_malloc_mutex)
! #define UNLOCK()   pthread_mutex_unlock (&_malloc_mutex)
  #define LOCK_ALIGNED_BLOCKS()     pthread_mutex_lock (&_aligned_blocks_mutex)
  #define UNLOCK_ALIGNED_BLOCKS()   pthread_mutex_unlock (&_aligned_blocks_mutex)
  #else
--- 246,260 ----
  
  #ifdef USE_PTHREAD
  extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
! extern int _malloc_thread_enabled_p;
! #define LOCK() \
!   do { \
!     if (_malloc_thread_enabled_p) pthread_mutex_lock (&_malloc_mutex); \
!   } while (0)
! #define UNLOCK() \
!   do { \
!     if (_malloc_thread_enabled_p) pthread_mutex_unlock (&_malloc_mutex); \
!   } while (0)
  #define LOCK_ALIGNED_BLOCKS()     pthread_mutex_lock (&_aligned_blocks_mutex)
  #define UNLOCK_ALIGNED_BLOCKS()   pthread_mutex_unlock (&_aligned_blocks_mutex)
  #else
*************** register_heapinfo ()
*** 563,568 ****
--- 574,596 ----
  #ifdef USE_PTHREAD
  pthread_mutex_t _malloc_mutex = PTHREAD_MUTEX_INITIALIZER;
  pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER;
+ int _malloc_thread_enabled_p;
+ 
+ /* Set up mutexes and make malloc etc. thread-safe.  */
+ void
+ malloc_enable_thread ()
+ {
+   if (_malloc_thread_enabled_p)
+     return;
+ 
+   /* Some pthread implementations call malloc for statically
+      initialized mutexes when they are used first.  To avoid such a
+      situation, we initialize mutexes here while their use is
+      disabled in malloc etc.  */
+   pthread_mutex_init (&_malloc_mutex, NULL);
+   pthread_mutex_init (&_aligned_blocks_mutex, NULL);
+   _malloc_thread_enabled_p = 1;
+ }
  #endif
  
  static void

  reply	other threads:[~2007-08-06  8:47 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-27 16:05 emacs-unicode-2 bootstrap on FreeBSD (temacs coredump) Damien Deville
2007-07-29 10:13 ` Jan Djärv
2007-07-31 19:09   ` Herbert J. Skuhra
2007-08-01  8:46     ` YAMAMOTO Mitsuharu
2007-08-01  9:20       ` Jan Djärv
2007-08-01  9:35         ` YAMAMOTO Mitsuharu
2007-08-01 10:07           ` YAMAMOTO Mitsuharu
2007-08-01 10:42             ` YAMAMOTO Mitsuharu
2007-08-01 11:53               ` Jan Djärv
2007-08-01 11:54                 ` Jan Djärv
2007-08-01 14:38                   ` Miles Bader
2007-08-01 18:27               ` Jan D.
2007-08-06  8:47                 ` YAMAMOTO Mitsuharu [this message]
2007-08-06 10:04                   ` YAMAMOTO Mitsuharu
2007-08-06 18:17                     ` Herbert J. Skuhra
2007-08-06 21:09                       ` Ryan Yeske
2007-08-07  8:05                         ` Jan Djärv
2007-08-07  9:22                           ` YAMAMOTO Mitsuharu
2007-08-01 11:52             ` Jan Djärv

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=wlhcnd59s4.wl%mituharu@math.s.chiba-u.ac.jp \
    --to=mituharu@math.s.chiba-u.ac.jp \
    --cc=emacs-devel@gnu.org \
    --cc=h.skuhra@gmail.com \
    --cc=jan.h.d@swipnet.se \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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