# Threads and fake forking

**URL:** <https://www.ruby-forum.com/t/threads-and-fake-forking/65729>\
**Category:** Ruby\
**Created:** [August 20, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/threads-and-fake-forking/65729 "2006-08-20T23:17:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Logan\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e47774/32.png) [@Logan\_C](https://www.ruby-forum.com/u/Logan_C)\
**Post date:** [August 20, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/threads-and-fake-forking/65729/1 "2006-08-20T23:17:37Z")

</div>

Today I was thinking about how you could use a Thread + Continuation  
to create a new thread with the interface of fork. Apparently I was  
mistaken.

class Thread  
def self.vfork  
callcc do |cc|  
Thread.new { cc.call(nil) }  
end  
end  
end

thread = Thread.vfork  
p thread

I don’t know what exactly happens, but it definitely isn’t  
nil  
#Thread:1234

as I was hopping

I could almost see just  
nil

showing up but that’s not what happens.

Instead I just get  
#\<Thread:1234 dead\>

Anyone have a cool explanation?

---

<div class="post-metadata">

**Author:** ![Logan\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e47774/32.png) [@Logan\_C](https://www.ruby-forum.com/u/Logan_C)\
**Post date:** [August 21, 2006, 12:13am UTC](https://www.ruby-forum.com/t/threads-and-fake-forking/65729/2 "2006-08-21T00:13:42Z")

</div>

On 8/20/06, Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Anyone have a cool explanation?

Ruby errors in a thread often don’t show up.

Thread.new { cc.call(nil) rescue $stderr \<\< $!.inspect }  
=\> #\<RuntimeError: continuation called across threads\>

Neat idea btw, too bad it doesn’t work.

---

<div class="post-metadata">

**Author:** ![Logan\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e47774/32.png) [@Logan\_C](https://www.ruby-forum.com/u/Logan_C)\
**Post date:** [August 21, 2006, 12:27am UTC](https://www.ruby-forum.com/t/threads-and-fake-forking/65729/3 "2006-08-21T00:27:44Z")

</div>

On Aug 20, 2006, at 3:11 PM, Sander L. wrote:

> On 8/20/06, Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Anyone have a cool explanation?
> 
> Ruby errors in a thread often don’t show up.
> 
> Thread.new { cc.call(nil) rescue $stderr \<\< $!.inspect }  
> =\> #\<RuntimeError: continuation called across threads\>
> 
> Neat idea btw, too bad it doesn’t work.

Add Thread.abort\_on\_exception = true

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Logan\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e47774/32.png) [@Logan\_C](https://www.ruby-forum.com/u/Logan_C)\
**Post date:** [August 21, 2006, 1:51pm UTC](https://www.ruby-forum.com/t/threads-and-fake-forking/65729/4 "2006-08-21T13:51:12Z")

</div>

Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> > Neat idea btw, too bad it doesn’t work.
> 
> Add Thread.abort\_on\_exception = true

Why is this not set by default, btw? Tracking such bugs down is a  
major annoyance.

---

<div class="post-metadata">

**Author:** ![Logan\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e47774/32.png) [@Logan\_C](https://www.ruby-forum.com/u/Logan_C)\
**Post date:** [August 21, 2006, 2:29pm UTC](https://www.ruby-forum.com/t/threads-and-fake-forking/65729/5 "2006-08-21T14:29:16Z")

</div>

On Aug 20, 2006, at 6:11 PM, Sander L. wrote:

> On 8/20/06, Logan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Anyone have a cool explanation?
> 
> Ruby errors in a thread often don’t show up.
> 
> Thread.new { cc.call(nil) rescue $stderr \<\< $!.inspect }  
> =\> #\<RuntimeError: continuation called across threads\>
> 
> Neat idea btw, too bad it doesn’t work.

That’s disappointing. I didn’t really want to call it across threads  
either (I wanted more like a thread-local “copy” of the  
continuation). You can’t always get what you want I suppose.
