diff --git a/lib/chibi/process.sld b/lib/chibi/process.sld index 516aa3c0..2744a26e 100644 --- a/lib/chibi/process.sld +++ b/lib/chibi/process.sld @@ -1,6 +1,6 @@ (define-library (chibi process) - (export exit sleep alarm fork kill execute waitpid system + (export exit sleep alarm %fork fork kill execute waitpid system process-command-line process-running? set-signal-action! make-signal-set signal-set? signal-set-contains? diff --git a/lib/chibi/process.stub b/lib/chibi/process.stub index 71d5e7db..8714267d 100644 --- a/lib/chibi/process.stub +++ b/lib/chibi/process.stub @@ -90,10 +90,13 @@ (define-c unsigned-int sleep (unsigned-int)) ;;> Fork the current process. Returns \rawcode{0} for the newly -;;> created process, and the process id of the new process for -;;> the parent. +;;> created process, and the process id of the new process for the +;;> parent. If multiple threads are active, they are forked as well. +;;> Use \scheme{fork} to also kill all other threads. -(define-c pid_t fork ()) +(define-c pid_t (%fork fork) ()) + +(define-c pid_t (fork sexp_fork_and_kill_threads) ((value ctx sexp))) (define-c-const int (wait/no-hang "WNOHANG")) diff --git a/lib/chibi/signal.c b/lib/chibi/signal.c index c82cf16b..10591a4f 100644 --- a/lib/chibi/signal.c +++ b/lib/chibi/signal.c @@ -117,6 +117,18 @@ static sexp sexp_pid_cmdline (sexp ctx, int pid) { #endif +static pid_t sexp_fork_and_kill_threads (sexp ctx) { + pid_t res = fork(); +#if SEXP_USE_GREEN_THREADS + if (res == 0) { /* child */ + sexp_global(ctx, SEXP_G_THREADS_FRONT) = SEXP_NULL; + sexp_global(ctx, SEXP_G_THREADS_BACK) = SEXP_NULL; + sexp_global(ctx, SEXP_G_THREADS_PAUSED) = SEXP_NULL; + } +#endif + return res; +} + static void sexp_init_signals (sexp ctx, sexp env) { call_sigaction.sa_sigaction = sexp_call_sigaction; #if SEXP_USE_GREEN_THREADS