Threads and fake forking

L

Logan Capaldo

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?
 
S

Sander Land

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.
 
E

Eric Hodel

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
 
L

Logan Capaldo

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top