diff --git a/libguile/scmsigs.c b/libguile/scmsigs.c index 86fce0f..e062f24 100644 --- a/libguile/scmsigs.c +++ b/libguile/scmsigs.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2004, 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2004, 2006, 2007, 2008, 2009, 2011, 2012 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -183,6 +183,12 @@ read_signal_pipe_data (void * data) return NULL; } +/* Lock to protect async queuing. Since `system-async-mark' conses, and + thus acquires the GC lock, this lock ensures that the signal thread + doesn't call `system-async-mark' in the middle of a `fork'. */ +static scm_i_pthread_mutex_t signal_async_mutex = + SCM_I_PTHREAD_MUTEX_INITIALIZER; + static SCM signal_delivery_thread (void *data) { @@ -212,7 +218,11 @@ signal_delivery_thread (void *data) h = SCM_SIMPLE_VECTOR_REF (signal_handler_asyncs, sig); t = SCM_SIMPLE_VECTOR_REF (signal_handler_threads, sig); if (scm_is_true (h)) + { + scm_i_pthread_mutex_lock (&signal_async_mutex); scm_system_async_mark_for_thread (h, t); + scm_i_pthread_mutex_unlock (&signal_async_mutex); + } } else if (sigdata.n == 0) break; /* the signal pipe was closed. */ @@ -713,6 +723,8 @@ scm_init_scmsigs () signal_handler_asyncs = scm_c_make_vector (NSIG, SCM_BOOL_F); signal_handler_threads = scm_c_make_vector (NSIG, SCM_BOOL_F); + scm_c_atfork_lock_static_mutex (&signal_async_mutex); + for (i = 0; i < NSIG; i++) { #ifdef HAVE_SIGACTION