On Wed, Nov 19, 2008 at 20:34, Urabe Shyouhei <shyouhei / ruby-lang.org> wrote:
> Brian Mitchell wrote:
>> On Wed, Nov 19, 2008 at 17:41, Aman Gupta <rubytalk / tmm1.net> wrote:
>>
>>>> Fiber in 1.9 equals to Thread of 1.8.
>>>>
>>> How can I implement the Fiber API (Fiber.yield and Fiber#resume) in
>>> 1.8. Is it possible to use:
>>>
>>>  rb_thread_save_context(fiber->saved_thread);
>>>  rb_thread_restore_context(fiber->saved_thread, RESTORE_NORMAL);
>>>
>>>  Aman
>>>
>>
>> It is possible to do something like Fibers quite easily with callcc
>> but it won't be nearly as efficient or safe.
>>
>> Brian.
>>
>
> I'm sorry to inform you that 1.8 threads are implemented on top of
> callcc, which means,
> 1.8 threads == ( 1.9 fibers == 1.8 continuations ) + preemption.
> They all have identical implementation, hence have the exactly same
> efficacy.

1.8 threads do have efficiency problems as well but 1.9 Fibers seem to
be much more effective (about 5x faster for a crude round trip context
switch -- I need to update my build to have accurate numbers, but I
would guess that the benefit still holds). As for safety of 1.8's
callcc, I was referring to the ease of memory leaks that are caused by
the stack copying since the GC is conservative. I don't know if 1.9's
Fiber currently suffers from the same risk or not as I don't know the
details of the implementation.

Brian.