From: KUBO Takehiro Date: 2007-03-17T18:36:07+09:00 Subject: [ruby-dev:30618] possible bug in rb_detach_process() 久保です。 waitpid 関係でちらほらソースを見ていたのですが、以下の部分は問題ではな いでしょうか? static VALUE detach_process_watcher(int *pid_p) { rb_pid_t cpid; int status; for (;;) { cpid = rb_waitpid(*pid_p, &status, WNOHANG); if (cpid != 0) return rb_last_status_get(); rb_thread_sleep(1); } } VALUE rb_detach_process(rb_pid_t pid) { return rb_thread_create(detach_process_watcher, (void*)&pid); } detach_process_watcher() に渡される引数は、rb_detach_process のスレッ ドのスタック上の値になっています。rb_waitpid() が実行される前に rb_detach_process のスレッドが動いてスタック上の値が書き変わったら、 rb_waitpid() に渡される pid はわけのわからない値になります。 正しくはこう? static VALUE detach_process_watcher(void *arg) <- int *pid_p を void *arg に { rb_pid_t pid = (int)arg; <- void* を rb_pid_t に戻す。 rb_pid_t cpid; int status; for (;;) { cpid = rb_waitpid(pid, &status, WNOHANG); <- *pid_p を pid に if (cpid != 0) return rb_last_status_get(); rb_thread_sleep(1); } } VALUE rb_detach_process(rb_pid_t pid) { return rb_thread_create(detach_process_watcher, (void*)pid); <- &pid を pid に }