# Child process forked from child thread does not call ruby\_cleanup

**URL:** <https://www.ruby-forum.com/t/child-process-forked-from-child-thread-does-not-call-ruby-cleanup/156427>\
**Category:** Development\
**Created:** [December 27, 2008, 11:46am UTC](https://www.ruby-forum.com/t/child-process-forked-from-child-thread-does-not-call-ruby-cleanup/156427 "2008-12-27T11:46:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [December 27, 2008, 11:46am UTC](https://www.ruby-forum.com/t/child-process-forked-from-child-thread-does-not-call-ruby-cleanup/156427/1 "2008-12-27T11:46:21Z")

</div>

e$B1sF#$G$9!#e(B

[ruby-dev:37447] e$B$rD4$Y$F$$$F5$$,$D$$$?$3$H$G$9$,!"e(B  
e$B;R%9%l%C%I$NCf$Ge(B fork e$B$7$?%W%m%;%9$,e(B ruby\_cleanup  
e$B$r$7$^$;$s!#e(B

$ ./miniruby -e ’  
at\_exit { p [:exit, $$] }  
Thread.new { p [fork ? :parent : :child, $$] }  
sleep 1  
’  
[:parent, 14543]  
[:child, 14546]  
[:exit, 14543]

1.8 e$B$G$"$l$P!"\>e$NNc$Ge(B [:exit, 14546] e$B$bI=\<($5$l$^$9!#e(B

at\_exit  
e$B$,\<B9T$5$l$J$$0J30$K!"%?%$%^!\<%9%l%C%I$@$1@8$-;D$C$F%W%m%;%9$,e(B  
e$B=_N;$7$J$$$H$+!"e(B(e$B$_$=$i$/e(B) IO  
e$B$N%U%!%$%J%i%$%6$,8F$S=P$5$l$J$$$H$+!“e(B  
e$B$$$m$$$m$HLdBj$,$”$k5$$,$7$^$9!#e(B

e$BKvHx$N%Q%C%A$G!“e(Bfork  
e$B$K$h$C$F%a%$%s%9%l%C%I$K\>:3J$7$?%9%l%C%I$N=\*N;;~$Ke(B  
ruby\_cleanup(state)  
e$B$r8F$V$h$&$K$J$j$^$9!#$,!”$$$m$$$m$HI{:nMQ$,$"$j$=$&$Ge(B  
e$BI]$$$G$9!#e(B

e$B$^$?!"$&$A$N4D6-e(B (Debian/lenny 32bit)  
e$B$G$O8=:\_$3$N%Q%C%A$r$"$F$J$/$F$be(B  
make test-all e$B$Ge(B SEGV  
e$B$7$?$j8G$^$C$?$j$9$k$N$G!"$A$c$s$H%F%9%H$G$-$F$be(B  
e$B$J$$$G$9!#e(B

e$B$I$&$7$?$b$s$G$7$g$&!#e(B

# Index: thread.c

— thread.c (revision 21097)  
+++ thread.c (working copy)  
@@ -427,6 +427,8 @@  
}  
TH\_POP\_TAG();

- if (main\_th == th) ruby\_cleanup(state);

- /\* locking\_mutex must be Qfalse \*/  
if (th-\>locking\_mutex != Qfalse) {  
rb\_bug(“thread\_start\_func\_2: locking\_mutex must not be set  
(%p:%“PRIxVALUE”)”,  
@@ -440,7 +442,7 @@  
}

- st\_delete\_wrap(th-\>vm-\>living\_threads, th-\>self);

- if (main\_th != th) st\_delete\_wrap(th-\>vm-\>living\_threads, th-\>self);

- if (th-\>vm-\>main\_thread == th) {

- rb\_thread\_stop\_timer\_thread();

- }  
native\_mutex\_unlock(&th-\>vm-\>global\_vm\_lock);
