Threads and fake forking

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?

On 8/20/06, Logan C. [email protected] 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.

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

On 8/20/06, Logan C. [email protected] 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. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

Eric H. [email protected] 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.

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

On 8/20/06, Logan C. [email protected] 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.