From: Jeremy Henty Date: 2002-12-16T17:20:44+09:00 Subject: Re: Ruby BUG when using PStore and fork In article <1039877646.586263.1663.nullmailer@picachu.netlab.jp>, Yukihiro Matsumoto wrote: > In message "Re: Ruby BUG when using PStore and fork" > on 02/12/14, Jeremy Henty writes: > >|> Update: PStore does not work well with fork, because "throw" does >|> not work with fork. >| >|So is this a bug or a feature? It is certainly alarming that you can >|get a BUG message with a few lines of pure Ruby. And why does the >|child lose the ability to throw? > > It's a feature. UNIX fork creates a copy of the process. The > parent process and the child process no longer shares memory space, > so that there's "almost" no way to send a exception (or a throw) > from a child to a parent. Perhaps I haven't made my question very clear. I understand how Unix fork works (as far as this discussion goes anyway) and I am not expecting the child to somehow throw to the parent. What I don't understand is why the child can't do a throw in its own memory space. After all, it contains its own copy of the stack. It should behave in every respect like its parent (unless it chooses to examine the return value of fork() or get_ppid() ...). Why can't it unwind its *own* stack (as copied from the parent) to the catch block? I tried tweaking my test program as follows: #!/usr/bin/env ruby catch :foo do fork throw :foo puts "You should not see this" end puts "Hi from #{$$}" and got: Hi from 20572 Hi from 20571 It works! So it seems that doing a throw after forking is actually OK. But if that is so, why is there a problem with "fork do throw :foo end"? Is it because fork assumes that the flow of control in any supplied block must terminate normally at the end of block rather than jumping out in the middle? I guess that is reasonable, in which case the solution is just a more helpful error message. Otherwise I am still confused and would appreciate any further explanations you can give. Regards, Jeremy Henty