mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 22:59:16 +02:00
(fork) now kills other threads atommically in the child. Use
(%fork) to keep other threads running in both parent and child.
This commit is contained in:
parent
44bf9837ca
commit
8629b10ca0
3 changed files with 19 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
(define-library (chibi process)
|
(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?
|
process-command-line process-running?
|
||||||
set-signal-action! make-signal-set
|
set-signal-action! make-signal-set
|
||||||
signal-set? signal-set-contains?
|
signal-set? signal-set-contains?
|
||||||
|
|
|
@ -90,10 +90,13 @@
|
||||||
(define-c unsigned-int sleep (unsigned-int))
|
(define-c unsigned-int sleep (unsigned-int))
|
||||||
|
|
||||||
;;> Fork the current process. Returns \rawcode{0} for the newly
|
;;> Fork the current process. Returns \rawcode{0} for the newly
|
||||||
;;> created process, and the process id of the new process for
|
;;> created process, and the process id of the new process for the
|
||||||
;;> the parent.
|
;;> 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"))
|
(define-c-const int (wait/no-hang "WNOHANG"))
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,18 @@ static sexp sexp_pid_cmdline (sexp ctx, int pid) {
|
||||||
|
|
||||||
#endif
|
#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) {
|
static void sexp_init_signals (sexp ctx, sexp env) {
|
||||||
call_sigaction.sa_sigaction = sexp_call_sigaction;
|
call_sigaction.sa_sigaction = sexp_call_sigaction;
|
||||||
#if SEXP_USE_GREEN_THREADS
|
#if SEXP_USE_GREEN_THREADS
|
||||||
|
|
Loading…
Add table
Reference in a new issue