summaryrefslogtreecommitdiff
path: root/libguile/posix.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2012-02-24 11:20:21 +0100
committerAndy Wingo <wingo@pobox.com>2012-02-24 11:20:21 +0100
commit415e00fc57e6d734d90b3a7e2324437ccdf406a7 (patch)
tree3b011d8a5409daaa12004cd54a85ea736719d11a /libguile/posix.c
parent508e4a55df353ec50f005307eb98557c7da79c82 (diff)
downloadguile-415e00fc57e6d734d90b3a7e2324437ccdf406a7.tar.gz
signal an error on multithreaded fork
* libguile/posix.c (scm_fork): Signal an error if a `fork' is attempted after threads have been spawned. * test-suite/tests/00-socket.test: Moved here, from socket.test, so as to run before any threads are created. * test-suite/Makefile.am: Adapt.
Diffstat (limited to 'libguile/posix.c')
-rw-r--r--libguile/posix.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libguile/posix.c b/libguile/posix.c
index 4f8b8ac7a..5e5862436 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 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
@@ -1248,6 +1248,18 @@ SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0,
#define FUNC_NAME s_scm_fork
{
int pid;
+ if (scm_ilength (scm_all_threads ()) != 1)
+ /* Other threads may be holding on to resources that Guile needs --
+ it is not safe to permit one thread to fork while others are
+ running.
+
+ In addition, POSIX clearly specifies that if a multi-threaded
+ program forks, the child must only call functions that are
+ async-signal-safe. We can't guarantee that in general. The best
+ we can do is to allow forking only very early, before any call to
+ sigaction spawns the signal-handling thread. */
+ SCM_MISC_ERROR ("attempt to fork while multiple threads are running",
+ SCM_EOL);
pid = fork ();
if (pid == -1)
SCM_SYSERROR;