unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* null-threads: keys are destroyed too early
@ 2008-02-27 16:17 Matthias Drochner
  0 siblings, 0 replies; only message in thread
From: Matthias Drochner @ 2008-02-27 16:17 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 2204 bytes --]


The "autogen" program crashes on exit if built against
a guile which doesn't use threads.
Here is a stacktrace:
#0  0xbbb902d1 in scm_make_srcprops () from /usr/pkg/lib/libguile.so.17
#1  0xbbb8b322 in scm_read_sexp () from /usr/pkg/lib/libguile.so.17
#2  0xbbb8a3f9 in scm_read_expression () from /usr/pkg/lib/libguile.so.17
#3  0xbbb8b1dc in scm_read_sexp () from /usr/pkg/lib/libguile.so.17
#4  0xbbb8a3f9 in scm_read_expression () from /usr/pkg/lib/libguile.so.17
#5  0xbbb8b1dc in scm_read_sexp () from /usr/pkg/lib/libguile.so.17
#6  0xbbb8a3f9 in scm_read_expression () from /usr/pkg/lib/libguile.so.17
#7  0x08050b3b in ag_scm_c_eval_string_from_file_line ()
#8  0x0805bbbd in doneCheck ()
#9  0xbba6b999 in __cxa_finalize () from /usr/lib/libc.so.12
#10 0xbba6b822 in exit () from /usr/lib/libc.so.12

The following happens: autogen registers an atexit() function
which calls ag_scm_c_eval_string_from_file_line().
On exit, this eventually calls scm_make_srcprops(), which
uses SCM_CRITICAL_SECTION_START, which in turn references
SCM_I_CURRENT_THREAD. The latter is implemented by
pthread_getspecific(), or rather its replacement in null-threads.c.

The emulated pthread_key_create() in null-threads.c also
registers an atexit() function which destroys the pthread_keys
allocated by the process. Since atexit() functions are
called in reverse order, this destroy_keys() function is
called before the doneCheck() above.

So SCM_I_CURRENT_THREAD tries to use a destroyed key,
leading to the crash.

The appended patch avoids the problem.

best regards
Matthias





-------------------------------------------------------------------
-------------------------------------------------------------------
Forschungszentrum Juelich GmbH
52425 Juelich

Sitz der Gesellschaft: Juelich
Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498
Vorsitzende des Aufsichtsrats: MinDir'in Baerbel Brumme-Bothe
Geschaeftsfuehrung: Prof. Dr. Achim Bachem (Vorsitzender),
Dr. Ulrich Krafft (stellv. Vorsitzender), Prof. Dr. Harald Bolt,
Dr. Sebastian M. Schmidt
-------------------------------------------------------------------
-------------------------------------------------------------------

[-- Attachment #2: patch-ak --]
[-- Type: text/plain , Size: 385 bytes --]

$NetBSD$

--- libguile/null-threads.c.orig	2008-01-04 14:43:50.000000000 +0100
+++ libguile/null-threads.c
@@ -47,8 +47,10 @@ int
 scm_i_pthread_key_create (scm_i_pthread_key_t *key,
 			  void (*destr_func) (void *))
 {
+#if 0 /* keys are needed by other atexit() functions */
   if (all_keys == NULL)
     atexit (destroy_keys);
+#endif
 
   key->next = all_keys;
   all_keys = key;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-27 16:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-27 16:17 null-threads: keys are destroyed too early Matthias Drochner

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