From 6e0c6ac3be8069e939748b00febcf4411ce905cb Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 18 Aug 2007 06:59:54 +0000 Subject: [PATCH] * process.c (detach_process_watcher): should not pass the pointer to an auto variable to the thread to be created. pointed and fix by KUBO Takehiro [ruby-dev:30618] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ process.c | 16 +++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 973c2b0c2e..729ef49743 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Aug 18 15:59:52 2007 Nobuyoshi Nakada + + * process.c (detach_process_watcher): should not pass the pointer + to an auto variable to the thread to be created. pointed and + fix by KUBO Takehiro [ruby-dev:30618] + Sat Aug 18 15:52:50 2007 Nobuyoshi Nakada * insnhelper.ci (vm_send_optimize): use MEMMOVE to shift values inside diff --git a/process.c b/process.c index 97bbda935e..fe954601b0 100644 --- a/process.c +++ b/process.c @@ -860,22 +860,21 @@ proc_waitall(void) } static VALUE -detach_process_watcher(int *pid_p) +detach_process_watcher(void *arg) { - rb_pid_t cpid; + rb_pid_t cpid, pid = (rb_pid_t)arg; int status; - for (;;) { - cpid = rb_waitpid(*pid_p, &status, WNOHANG); - if (cpid != 0) return rb_last_status_get(); - rb_thread_sleep(1); + while ((cpid = rb_waitpid(pid, &status, 0)) == 0) { + /* wait while alive */ } + return rb_last_status_get(); } VALUE rb_detach_process(rb_pid_t pid) { - return rb_thread_create(detach_process_watcher, (void*)&pid); + return rb_thread_create(detach_process_watcher, (void*)pid); } @@ -891,8 +890,7 @@ rb_detach_process(rb_pid_t pid) * separate Ruby thread whose sole job is to reap the status of the * process _pid_ when it terminates. Use detach * only when you do not intent to explicitly wait for the child to - * terminate. detach only checks the status - * periodically (currently once each second). + * terminate. * * The waiting thread returns the exit status of the detached process * when it terminates, so you can use Thread#join to