diff options
author | Andy Wingo <wingo@pobox.com> | 2013-01-17 12:38:56 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2013-01-17 12:38:56 +0100 |
commit | a796d0a95442b379a9ff2cdf9e0eb6efccc5dc08 (patch) | |
tree | 05142a024acdb1691f7617293cf1da92ddfd3ae3 /libguile/posix.c | |
parent | 36c210d14e8572939901b9251492a3f4bf94988c (diff) | |
download | guile-a796d0a95442b379a9ff2cdf9e0eb6efccc5dc08.tar.gz |
warn on multithreaded fork
* libguile/posix.c (scm_fork): Issue a warning on a multithreaded fork.
* doc/ref/posix.texi (Processes): Add note about multithreaded fork.
* 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.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libguile/posix.c b/libguile/posix.c index 4d5fdcf96..324f21b78 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1249,6 +1249,22 @@ 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_display + (scm_from_latin1_string + ("warning: call to primitive-fork while multiple threads are running;\n" + " further behavior unspecified. See \"Processes\" in the\n" + " manual, for more information.\n"), + scm_current_warning_port ()); pid = fork (); if (pid == -1) SCM_SYSERROR; |