From: Lucas Nussbaum Date: 2011-08-29T14:59:22+09:00 Subject: [ruby-core:39178] Re: [Ruby 1.9 - Bug #5239] bootstraptest/runner.rb: assert_normal_exit logic broken on Debian/GNU kFreeBSD On 29/08/11 at 13:56 +0900, Lucas Nussbaum wrote: > On 29/08/11 at 12:43 +0900, KOSAKI Motohiro wrote: > > > I've just checked, and FreeBSD 8.2 is also affected by this issue. > > > Test script: > > > system("false") > > > sleep 0.5 > > > th = Thread::new { $? } > > > p th > > > th.join > > > p th > > > p th.value > > > > This is buggy. $? is thread local storage variable. last exit value > > was set to main thread. > > because system() was called from it. Therefore it fail even if run on linux. > > Right, sorry. > > > In the other hand, on assert_normal_exit(), io.close is called from > > sub thread. it's a source > > of difference. > > Right, it changes the order of termination. Err, no, it doesn't. the popen process still ends before the thread. I don't see why io.close would be a source of difference? In any case, it's a bug in Debian GNU/kfreebsd. With the following test case: <------------- #include #include #include #include #include #include int retval; int pid; void * thread_get_retval(void *arg) { if (waitpid(pid, &retval, 0) == -1) { perror("waitpid"); exit(1); } printf("hello\n"); return(0); } int main() { pthread_t tid; if ((pid = fork()) == 0) { return 42; } printf("PID: %d\n", pid); if (pthread_create(&tid, NULL, thread_get_retval, NULL)) { perror("pthread_create"); exit(1); } if (pthread_join( tid, NULL )) { perror("pthread_join"); exit(1); } printf("Retval: %d\n", WEXITSTATUS(retval)); return 0; } --------------> Debian GNU/Linux: PID: 27610 hello Retval: 42 FreeBSD: PID: 1172 hello Retval: 42 Debian GNU/kFreeBSD: ./debian-kfreebsd-amd64:~# ./forkthread PID: 719 waitpid: No child processes Do you still want to apply my patch? I could apply it only in the Debian package if you prefer. - Lucas