[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Threads and fake forking

Logan Capaldo

8/20/2006 9:16:00 PM

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?


4 Answers

Sander Land

8/20/2006 10:12:00 PM

0

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

8/20/2006 10:25:00 PM

0

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.

Add Thread.abort_on_exception = true

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

http://trackmap.rob...



Christian Neukirchen

8/21/2006 11:50:00 AM

0

Eric Hodel <drbrain@segment7.net> writes:

> 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.
>
> Add Thread.abort_on_exception = true

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

> Eric Hodel - drbrain@segment7.net - http://blog.se...
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Logan Capaldo

8/21/2006 12:27:00 PM

0


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

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.