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?

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 8/20/06, Logan Capaldo <logancapaldo@gmail.com> wrote:

Anyone have a cool explanation?

Add Thread.abort_on_exception = true

···

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

On 8/20/06, Logan Capaldo <logancapaldo@gmail.com> 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.

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com

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.

···

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

On 8/20/06, Logan Capaldo <logancapaldo@gmail.com> 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.

Eric Hodel <drbrain@segment7.net> writes:

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

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

···

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

On 8/20/06, Logan Capaldo <logancapaldo@gmail.com> wrote:

Eric Hodel - drbrain@segment7.net - http://blog.segment7.net

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org