* emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
@ 2007-07-27 16:05 Damien Deville
2007-07-29 10:13 ` Jan Djärv
0 siblings, 1 reply; 19+ messages in thread
From: Damien Deville @ 2007-07-27 16:05 UTC (permalink / raw)
To: emacs-devel
Hi emacs-devel,
On FreeBSD 6.2 with an up to date checkout of emacs-unicode-2 CVS temacs
coredump while bootstraping.
`/bin/pwd`/temacs --batch --load loadup bootstrap
Segmentation fault (core dumped)
gmake[2]: *** [bootstrap-emacs] Error 139
Launching gdb on the core shows the following trace:
(gdb) bt
#0 0x28a007a0 in pthread_once () from /lib/libpthread.so.2
#1 0x081a6ea1 in __malloc_initialize () at gmalloc.c:615
#2 0x081a6ed1 in malloc (size=68) at gmalloc.c:969
#3 0x28a00c0d in pthread_mutex_init () from /lib/libpthread.so.2
#4 0x28a00daf in _pthread_mutex_init () from /lib/libpthread.so.2
#5 0x28a0a8a5 in pthread_setconcurrency () from /lib/libpthread.so.2
#6 0x28a045be in _pthread_mutex_lock () from /lib/libpthread.so.2
#7 0x28a007ca in pthread_once () from /lib/libpthread.so.2
#8 0x081a6ea1 in __malloc_initialize () at gmalloc.c:615
#9 0x081a6ed1 in malloc (size=68) at gmalloc.c:969
#10 0x28a00c0d in pthread_mutex_init () from /lib/libpthread.so.2
#11 0x28a00daf in _pthread_mutex_init () from /lib/libpthread.so.2
#12 0x28a0a8a5 in pthread_setconcurrency () from /lib/libpthread.so.2
#13 0x28a045be in _pthread_mutex_lock () from /lib/libpthread.so.2
#14 0x28a007ca in pthread_once () from /lib/libpthread.so.2
#15 0x081a6ea1 in __malloc_initialize () at gmalloc.c:615
#16 0x081a6ed1 in malloc (size=68) at gmalloc.c:969
#17 0x28a00c0d in pthread_mutex_init () from /lib/libpthread.so.2
#18 0x28a00daf in _pthread_mutex_init () from /lib/libpthread.so.2
#19 0x28a0a8a5 in pthread_setconcurrency () from /lib/libpthread.so.2
#20 0x28a045be in _pthread_mutex_lock () from /lib/libpthread.so.2
#21 0x28a007ca in pthread_once () from /lib/libpthread.so.2
#22 0x081a6ea1 in __malloc_initialize () at gmalloc.c:615
---Type <return> to continue, or q <return> to quit---
The rest of the backtrace contains the same recursive call to
__malloc_initialize()
Thanks in advance,
Damien
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
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
0 siblings, 1 reply; 19+ messages in thread
From: Jan Djärv @ 2007-07-29 10:13 UTC (permalink / raw)
To: damien.deville; +Cc: emacs-devel
I've checked in a fix in CVS HEAD. It should propagate to unicode2, please
try it then.
Jan D.
Damien Deville skrev:
> Hi emacs-devel,
>
> On FreeBSD 6.2 with an up to date checkout of emacs-unicode-2 CVS temacs
> coredump while bootstraping.
>
> `/bin/pwd`/temacs --batch --load loadup bootstrap
> Segmentation fault (core dumped)
> gmake[2]: *** [bootstrap-emacs] Error 139
>
> Launching gdb on the core shows the following trace:
>
> (gdb) bt
> #0 0x28a007a0 in pthread_once () from /lib/libpthread.so.2
> #1 0x081a6ea1 in __malloc_initialize () at gmalloc.c:615
> #2 0x081a6ed1 in malloc (size=68) at gmalloc.c:969
> #3 0x28a00c0d in pthread_mutex_init () from /lib/libpthread.so.2
> #4 0x28a00daf in _pthread_mutex_init () from /lib/libpthread.so.2
> #5 0x28a0a8a5 in pthread_setconcurrency () from /lib/libpthread.so.2
> #6 0x28a045be in _pthread_mutex_lock () from /lib/libpthread.so.2
> #7 0x28a007ca in pthread_once () from /lib/libpthread.so.2
> #8 0x081a6ea1 in __malloc_initialize () at gmalloc.c:615
> #9 0x081a6ed1 in malloc (size=68) at gmalloc.c:969
> #10 0x28a00c0d in pthread_mutex_init () from /lib/libpthread.so.2
> #11 0x28a00daf in _pthread_mutex_init () from /lib/libpthread.so.2
> #12 0x28a0a8a5 in pthread_setconcurrency () from /lib/libpthread.so.2
> #13 0x28a045be in _pthread_mutex_lock () from /lib/libpthread.so.2
> #14 0x28a007ca in pthread_once () from /lib/libpthread.so.2
> #15 0x081a6ea1 in __malloc_initialize () at gmalloc.c:615
> #16 0x081a6ed1 in malloc (size=68) at gmalloc.c:969
> #17 0x28a00c0d in pthread_mutex_init () from /lib/libpthread.so.2
> #18 0x28a00daf in _pthread_mutex_init () from /lib/libpthread.so.2
> #19 0x28a0a8a5 in pthread_setconcurrency () from /lib/libpthread.so.2
> #20 0x28a045be in _pthread_mutex_lock () from /lib/libpthread.so.2
> #21 0x28a007ca in pthread_once () from /lib/libpthread.so.2
> #22 0x081a6ea1 in __malloc_initialize () at gmalloc.c:615
> ---Type <return> to continue, or q <return> to quit---
>
> The rest of the backtrace contains the same recursive call to
> __malloc_initialize()
>
>
> Thanks in advance,
> Damien
>
>
> _______________________________________________
> Emacs-devel mailing list
> Emacs-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-07-29 10:13 ` Jan Djärv
@ 2007-07-31 19:09 ` Herbert J. Skuhra
2007-08-01 8:46 ` YAMAMOTO Mitsuharu
0 siblings, 1 reply; 19+ messages in thread
From: Herbert J. Skuhra @ 2007-07-31 19:09 UTC (permalink / raw)
To: emacs-devel
Jan Djärv skrev:
> I've checked in a fix in CVS HEAD. It should propagate to unicode2, please
> try it then.
>
> Jan D.
Thanks. But the problem persists in CVS HEAD:
% ./configure --prefix=/usr/local/emacs --with-gtk --build=i386-freebsd
% make bootstrap
Build error:
./temacs --batch --load loadup bootstrap
*** Signal 11
(gdb) run
Starting program: /home/herbert/cvs/tmp/emacs/src/temacs --batch --load
loadup bootstrap
Program received signal SIGSEGV, Segmentation fault.
0x289fcd86 in _pthread_mutex_init () from /lib/libpthread.so.2
#0 0x289fcd86 in _pthread_mutex_init () from /lib/libpthread.so.2
#1 0x28a068a5 in pthread_setconcurrency () from /lib/libpthread.so.2
#2 0x28a007aa in pthread_mutex_lock () from /lib/libpthread.so.2
#3 0x0818c465 in _malloc_internal (size=68) at gmalloc.c:953
#4 0x289fcc0d in pthread_mutex_init () from /lib/libpthread.so.2
#5 0x289fcdaf in _pthread_mutex_init () from /lib/libpthread.so.2
#6 0x28a068a5 in pthread_setconcurrency () from /lib/libpthread.so.2
#7 0x28a007aa in pthread_mutex_lock () from /lib/libpthread.so.2
#8 0x0818c465 in _malloc_internal (size=68) at gmalloc.c:953
#9 0x289fcc0d in pthread_mutex_init () from /lib/libpthread.so.2
#10 0x289fcdaf in _pthread_mutex_init () from /lib/libpthread.so.2
#11 0x28a068a5 in pthread_setconcurrency () from /lib/libpthread.so.2
#12 0x28a007aa in pthread_mutex_lock () from /lib/libpthread.so.2
#13 0x0818c465 in _malloc_internal (size=68) at gmalloc.c:953
#14 0x289fcc0d in pthread_mutex_init () from /lib/libpthread.so.2
...
...
...
When "--with-x-toolkit=motif" is used, make bootstrap is OK.
Hmm, Openmotif doesn't look that bad! :)
BR
Herbert
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-07-31 19:09 ` Herbert J. Skuhra
@ 2007-08-01 8:46 ` YAMAMOTO Mitsuharu
2007-08-01 9:20 ` Jan Djärv
0 siblings, 1 reply; 19+ messages in thread
From: YAMAMOTO Mitsuharu @ 2007-08-01 8:46 UTC (permalink / raw)
To: Herbert J. Skuhra; +Cc: emacs-devel
>>>>> On Tue, 31 Jul 2007 21:09:55 +0200, "Herbert J. Skuhra" <h.skuhra@gmail.com> said:
> Jan Djärv skrev:
>> I've checked in a fix in CVS HEAD. It should propagate to unicode2, please
>> try it then.
>>
>> Jan D.
> Thanks. But the problem persists in CVS HEAD:
> % ./configure --prefix=/usr/local/emacs --with-gtk --build=i386-freebsd
> % make bootstrap
> Build error:
> ./temacs --batch --load loadup bootstrap
> *** Signal 11
A comment in src/lib/libc/stdlib/malloc.c (FreeBSD Current) says:
/*
* Mutexes based on spinlocks. We can't use normal pthread mutexes, because
* they require malloc()ed memory.
*/
So it seems to be impossible to make src/gmalloc.c thread-safe only
using pthread mutexes.
I'm not sure if spinlocks are open to user applications, but anyway it
would be simpler to define SYSTEM_MALLOC when HAVE_GTK_AND_PTHREAD &&
!DOUG_LEA_MALLOC, and abandon emacs_blocked_malloc etc. on such
platforms. I don't care if my changes made to src/gmalloc.c for
thread-safety is reverted.
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-01 8:46 ` YAMAMOTO Mitsuharu
@ 2007-08-01 9:20 ` Jan Djärv
2007-08-01 9:35 ` YAMAMOTO Mitsuharu
0 siblings, 1 reply; 19+ messages in thread
From: Jan Djärv @ 2007-08-01 9:20 UTC (permalink / raw)
To: YAMAMOTO Mitsuharu; +Cc: Herbert J. Skuhra, emacs-devel
YAMAMOTO Mitsuharu skrev:
>
> A comment in src/lib/libc/stdlib/malloc.c (FreeBSD Current) says:
>
> /*
> * Mutexes based on spinlocks. We can't use normal pthread mutexes, because
> * they require malloc()ed memory.
> */
>
> So it seems to be impossible to make src/gmalloc.c thread-safe only
> using pthread mutexes.
Totally thread safe is impossible, but for Emacs we don't need that. It
should be OK to initialize gmalloc in a non-thread safe way because it is done
in main (or possibly before) before any threads are created.
>
> I'm not sure if spinlocks are open to user applications, but anyway it
> would be simpler to define SYSTEM_MALLOC when HAVE_GTK_AND_PTHREAD &&
> !DOUG_LEA_MALLOC, and abandon emacs_blocked_malloc etc. on such
> platforms. I don't care if my changes made to src/gmalloc.c for
> thread-safety is reverted.
That is always a possibility. I'll look into both.
Jan D.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-01 9:20 ` Jan Djärv
@ 2007-08-01 9:35 ` YAMAMOTO Mitsuharu
2007-08-01 10:07 ` YAMAMOTO Mitsuharu
0 siblings, 1 reply; 19+ messages in thread
From: YAMAMOTO Mitsuharu @ 2007-08-01 9:35 UTC (permalink / raw)
To: Jan Djärv; +Cc: Herbert J. Skuhra, emacs-devel
>>>>> On Wed, 01 Aug 2007 11:20:26 +0200, Jan Djärv <jan.h.d@swipnet.se> said:
> YAMAMOTO Mitsuharu skrev:
>>
>> A comment in src/lib/libc/stdlib/malloc.c (FreeBSD Current) says:
>>
>> /* * Mutexes based on spinlocks. We can't use normal pthread
>> mutexes, because * they require malloc()ed memory. */
>>
>> So it seems to be impossible to make src/gmalloc.c thread-safe only
>> using pthread mutexes.
> Totally thread safe is impossible, but for Emacs we don't need that.
> It should be OK to initialize gmalloc in a non-thread safe way
> because it is done in main (or possibly before) before any threads
> are created.
I didn't mean the initialization problem with respect to pthread_once.
The followup report shows that there's another infinite recursion like
pthread_mutex_lock -> -> malloc -> -> pthread_mutex_lock -> ... when a
certain (statically initialized) mutex is used first.
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
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:52 ` Jan Djärv
0 siblings, 2 replies; 19+ messages in thread
From: YAMAMOTO Mitsuharu @ 2007-08-01 10:07 UTC (permalink / raw)
To: Jan Djärv; +Cc: Herbert J. Skuhra, emacs-devel
>>>>> On Wed, 01 Aug 2007 18:35:40 +0900, YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> said:
>> Totally thread safe is impossible, but for Emacs we don't need
>> that. It should be OK to initialize gmalloc in a non-thread safe
>> way because it is done in main (or possibly before) before any
>> threads are created.
> I didn't mean the initialization problem with respect to
> pthread_once. The followup report shows that there's another
> infinite recursion like pthread_mutex_lock -> -> malloc -> ->
> pthread_mutex_lock -> ... when a certain (statically initialized)
> mutex is used first.
Ah, maybe I misunderstood what you mean. It might be possible to call
pthread_mutex_init for all malloc mutexes at the (non-thread-safe)
initialization stage with temporarily disabling the use of the
mutexes.
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
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 18:27 ` Jan D.
2007-08-01 11:52 ` Jan Djärv
1 sibling, 2 replies; 19+ messages in thread
From: YAMAMOTO Mitsuharu @ 2007-08-01 10:42 UTC (permalink / raw)
To: Jan Djärv; +Cc: Herbert J. Skuhra, emacs-devel
>>>>> On Wed, 01 Aug 2007 19:07:47 +0900, YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> said:
> It might be possible to call pthread_mutex_init for all malloc
> mutexes at the (non-thread-safe) initialization stage with
> temporarily disabling the use of the mutexes.
Could you try if this works? As usual, I can't test it myself.
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp
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 1 Aug 2007 10:35:05 -0000
*************** 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
--- 242,256 ----
#ifdef USE_PTHREAD
extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
! extern int _malloc_mutex_disabled_p;
! #define LOCK() \
! do { \
! if (!_malloc_mutex_disabled_p) pthread_mutex_lock (&_malloc_mutex); \
! } while (0)
! #define UNLOCK() \
! do { \
! if (!_malloc_mutex_disabled_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 ****
--- 570,576 ----
#ifdef USE_PTHREAD
pthread_mutex_t _malloc_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER;
+ int _malloc_mutex_disabled_p;
#endif
static void
*************** __malloc_initialize ()
*** 617,622 ****
--- 625,641 ----
malloc_initialize_1 ();
+ /* Some pthread implementations call malloc for statically
+ initialized mutexes when they are used first. To avoid such a
+ situation, we initialize mutexes here with temporarily disabling
+ the use of mutexes. */
+ #ifdef USE_PTHREAD
+ _malloc_mutex_disabled_p = 1;
+ pthread_mutex_init (&_malloc_mutex, NULL);
+ pthread_mutex_init (&_aligned_blocks_mutex, NULL);
+ _malloc_mutex_disabled_p = 0;
+ #endif
+
return __malloc_initialized;
}
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-01 10:07 ` YAMAMOTO Mitsuharu
2007-08-01 10:42 ` YAMAMOTO Mitsuharu
@ 2007-08-01 11:52 ` Jan Djärv
1 sibling, 0 replies; 19+ messages in thread
From: Jan Djärv @ 2007-08-01 11:52 UTC (permalink / raw)
To: YAMAMOTO Mitsuharu; +Cc: Herbert J. Skuhra, emacs-devel
YAMAMOTO Mitsuharu skrev:
> Ah, maybe I misunderstood what you mean. It might be possible to call
> pthread_mutex_init for all malloc mutexes at the (non-thread-safe)
> initialization stage with temporarily disabling the use of the
> mutexes.
Exactly.
Jan D.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
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 18:27 ` Jan D.
1 sibling, 1 reply; 19+ messages in thread
From: Jan Djärv @ 2007-08-01 11:53 UTC (permalink / raw)
To: YAMAMOTO Mitsuharu; +Cc: Herbert J. Skuhra, emacs-devel
YAMAMOTO Mitsuharu skrev:
>>>>>> On Wed, 01 Aug 2007 19:07:47 +0900, YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> said:
>
>> It might be possible to call pthread_mutex_init for all malloc
>> mutexes at the (non-thread-safe) initialization stage with
>> temporarily disabling the use of the mutexes.
>
> Could you try if this works? As usual, I can't test it myself.
I think we should call LOCK/UNLOCK on them also just to be sure.
You never know what those BDS guys are up to :-)
Jan D.
>
> YAMAMOTO Mitsuharu
> mituharu@math.s.chiba-u.ac.jp
>
> 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 1 Aug 2007 10:35:05 -0000
> *************** 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
> --- 242,256 ----
>
> #ifdef USE_PTHREAD
> extern pthread_mutex_t _malloc_mutex, _aligned_blocks_mutex;
> ! extern int _malloc_mutex_disabled_p;
> ! #define LOCK() \
> ! do { \
> ! if (!_malloc_mutex_disabled_p) pthread_mutex_lock (&_malloc_mutex); \
> ! } while (0)
> ! #define UNLOCK() \
> ! do { \
> ! if (!_malloc_mutex_disabled_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 ****
> --- 570,576 ----
> #ifdef USE_PTHREAD
> pthread_mutex_t _malloc_mutex = PTHREAD_MUTEX_INITIALIZER;
> pthread_mutex_t _aligned_blocks_mutex = PTHREAD_MUTEX_INITIALIZER;
> + int _malloc_mutex_disabled_p;
> #endif
>
> static void
> *************** __malloc_initialize ()
> *** 617,622 ****
> --- 625,641 ----
>
> malloc_initialize_1 ();
>
> + /* Some pthread implementations call malloc for statically
> + initialized mutexes when they are used first. To avoid such a
> + situation, we initialize mutexes here with temporarily disabling
> + the use of mutexes. */
> + #ifdef USE_PTHREAD
> + _malloc_mutex_disabled_p = 1;
> + pthread_mutex_init (&_malloc_mutex, NULL);
> + pthread_mutex_init (&_aligned_blocks_mutex, NULL);
> + _malloc_mutex_disabled_p = 0;
> + #endif
> +
> return __malloc_initialized;
> }
>
>
>
> _______________________________________________
> Emacs-devel mailing list
> Emacs-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-01 11:53 ` Jan Djärv
@ 2007-08-01 11:54 ` Jan Djärv
2007-08-01 14:38 ` Miles Bader
0 siblings, 1 reply; 19+ messages in thread
From: Jan Djärv @ 2007-08-01 11:54 UTC (permalink / raw)
To: YAMAMOTO Mitsuharu; +Cc: Herbert J. Skuhra, emacs-devel
Jan Djärv skrev:
>
>
> I think we should call LOCK/UNLOCK on them also just to be sure.
> You never know what those BDS guys are up to :-)
----------------------------^^^--- BSD obviously.
Jan D.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-01 11:54 ` Jan Djärv
@ 2007-08-01 14:38 ` Miles Bader
0 siblings, 0 replies; 19+ messages in thread
From: Miles Bader @ 2007-08-01 14:38 UTC (permalink / raw)
To: Jan Djärv; +Cc: Herbert J. Skuhra, YAMAMOTO Mitsuharu, emacs-devel
Jan Djärv <jan.h.d@swipnet.se> writes:
>> I think we should call LOCK/UNLOCK on them also just to be sure.
>> You never know what those BDS guys are up to :-)
>
> ----------------------------^^^--- BSD obviously.
You've clearly done too much LDS...
-Miles
--
I'd rather be consing.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-01 10:42 ` YAMAMOTO Mitsuharu
2007-08-01 11:53 ` Jan Djärv
@ 2007-08-01 18:27 ` Jan D.
2007-08-06 8:47 ` YAMAMOTO Mitsuharu
1 sibling, 1 reply; 19+ messages in thread
From: Jan D. @ 2007-08-01 18:27 UTC (permalink / raw)
To: YAMAMOTO Mitsuharu; +Cc: Herbert J. Skuhra, emacs-devel
YAMAMOTO Mitsuharu wrote:
>>>>>> On Wed, 01 Aug 2007 19:07:47 +0900, YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> said:
>>>>>>
>
>
>> It might be possible to call pthread_mutex_init for all malloc
>> mutexes at the (non-thread-safe) initialization stage with
>> temporarily disabling the use of the mutexes.
>>
>
> Could you try if this works? As usual, I can't test it myself.
>
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. 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).
There are spin locks available on BSD and GNU/Linux, see
pthread_spin_init. But that don't help for the pthread_self issue.
Sigh, back to the drawing board.
Jan D.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-01 18:27 ` Jan D.
@ 2007-08-06 8:47 ` YAMAMOTO Mitsuharu
2007-08-06 10:04 ` YAMAMOTO Mitsuharu
0 siblings, 1 reply; 19+ messages in thread
From: YAMAMOTO Mitsuharu @ 2007-08-06 8:47 UTC (permalink / raw)
To: Jan D.; +Cc: Herbert J. Skuhra, emacs-devel
>>>>> 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
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-06 8:47 ` YAMAMOTO Mitsuharu
@ 2007-08-06 10:04 ` YAMAMOTO Mitsuharu
2007-08-06 18:17 ` Herbert J. Skuhra
0 siblings, 1 reply; 19+ messages in thread
From: YAMAMOTO Mitsuharu @ 2007-08-06 10:04 UTC (permalink / raw)
To: Jan D.; +Cc: Herbert J. Skuhra, emacs-devel
>>>>> On Mon, 06 Aug 2007 17:47:55 +0900, YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> said:
> How about deferring mutex initializations until an interactive
> session starts? Could you try the patch below?
(UN)LOCK_ALIGNED_BLOCKS was not conditionalized. Please try this one
instead.
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 09:34:26 -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 09:34:26 -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,251 ****
#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
#define LOCK()
#define UNLOCK()
--- 246,272 ----
#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() \
! do { \
! if (_malloc_thread_enabled_p) \
! pthread_mutex_lock (&_aligned_blocks_mutex); \
! } while (0)
! #define UNLOCK_ALIGNED_BLOCKS() \
! do { \
! if (_malloc_thread_enabled_p) \
! pthread_mutex_unlock (&_aligned_blocks_mutex); \
! } while (0)
#else
#define LOCK()
#define UNLOCK()
*************** register_heapinfo ()
*** 563,568 ****
--- 584,630 ----
#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;
+
+ static void
+ malloc_atfork_handler_prepare ()
+ {
+ LOCK ();
+ LOCK_ALIGNED_BLOCKS ();
+ }
+
+ static void
+ malloc_atfork_handler_parent ()
+ {
+ UNLOCK_ALIGNED_BLOCKS ();
+ UNLOCK ();
+ }
+
+ static void
+ malloc_atfork_handler_child ()
+ {
+ UNLOCK_ALIGNED_BLOCKS ();
+ UNLOCK ();
+ }
+
+ /* 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);
+ pthread_atfork (malloc_atfork_handler_prepare,
+ malloc_atfork_handler_parent,
+ malloc_atfork_handler_child);
+ _malloc_thread_enabled_p = 1;
+ }
#endif
static void
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-06 10:04 ` YAMAMOTO Mitsuharu
@ 2007-08-06 18:17 ` Herbert J. Skuhra
2007-08-06 21:09 ` Ryan Yeske
0 siblings, 1 reply; 19+ messages in thread
From: Herbert J. Skuhra @ 2007-08-06 18:17 UTC (permalink / raw)
To: YAMAMOTO Mitsuharu; +Cc: Jan D., emacs-devel
On Mon, Aug 06, 2007 at 07:04:08PM +0900, YAMAMOTO Mitsuharu wrote:
> >>>>> On Mon, 06 Aug 2007 17:47:55 +0900, YAMAMOTO Mitsuharu
> >>>>> <mituharu@math.s.chiba-u.ac.jp> said:
>
> > How about deferring mutex initializations until an interactive
> > session starts? Could you try the patch below?
>
> (UN)LOCK_ALIGNED_BLOCKS was not conditionalized. Please try this one
> instead.
Arigatou.
With this patch the emacs build completes again on FreeBSD 6.2-STABLE!
---
This is GNU Emacs 22.1.50.1 (i386-pc-freebsd, GTK+ Version 2.10.14)
of 2007-08-06
---
Regards,
Herbert
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-06 18:17 ` Herbert J. Skuhra
@ 2007-08-06 21:09 ` Ryan Yeske
2007-08-07 8:05 ` Jan Djärv
0 siblings, 1 reply; 19+ messages in thread
From: Ryan Yeske @ 2007-08-06 21:09 UTC (permalink / raw)
To: Herbert J. Skuhra; +Cc: jan.h.d, mituharu, emacs-devel
"Herbert J. Skuhra" <h.skuhra@gmail.com> writes:
>> (UN)LOCK_ALIGNED_BLOCKS was not conditionalized. Please try this one
>> instead.
>
> Arigatou.
>
> With this patch the emacs build completes again on FreeBSD 6.2-STABLE!
And on OpenBSD 4.1/i386, which was having similar build problems before.
Thanks!
Ryan
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-06 21:09 ` Ryan Yeske
@ 2007-08-07 8:05 ` Jan Djärv
2007-08-07 9:22 ` YAMAMOTO Mitsuharu
0 siblings, 1 reply; 19+ messages in thread
From: Jan Djärv @ 2007-08-07 8:05 UTC (permalink / raw)
To: Ryan Yeske; +Cc: Herbert J. Skuhra, mituharu, emacs-devel
Ryan Yeske skrev:
> "Herbert J. Skuhra" <h.skuhra@gmail.com> writes:
>
>>> (UN)LOCK_ALIGNED_BLOCKS was not conditionalized. Please try this one
>>> instead.
>> Arigatou.
>>
>> With this patch the emacs build completes again on FreeBSD 6.2-STABLE!
>
> And on OpenBSD 4.1/i386, which was having similar build problems before.
>
> Thanks!
>
This should go into both HEAD and EMACS_22_BASE.
Jan D.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: emacs-unicode-2 bootstrap on FreeBSD (temacs coredump)
2007-08-07 8:05 ` Jan Djärv
@ 2007-08-07 9:22 ` YAMAMOTO Mitsuharu
0 siblings, 0 replies; 19+ messages in thread
From: YAMAMOTO Mitsuharu @ 2007-08-07 9:22 UTC (permalink / raw)
To: Jan Djärv; +Cc: Herbert J. Skuhra, Ryan Yeske, emacs-devel
>>>>> On Tue, 07 Aug 2007 10:05:37 +0200, Jan Djärv <jan.h.d@swipnet.se> said:
> Ryan Yeske skrev:
>> "Herbert J. Skuhra" <h.skuhra@gmail.com> writes:
>>
>>>> (UN)LOCK_ALIGNED_BLOCKS was not conditionalized. Please try this
>>>> one instead.
>>> Arigatou.
>>>
>>> With this patch the emacs build completes again on FreeBSD
>>> 6.2-STABLE!
>>
>> And on OpenBSD 4.1/i386, which was having similar build problems
>> before.
>>
>> Thanks!
>>
> This should go into both HEAD and EMACS_22_BASE.
Done.
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2007-08-07 9:22 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.