Brian Mitchell wrote:
> 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.
>   

Ko1 explained me about this.  According to him, 1.8 threads are slower
because context switching on 1.8 needs a lot of memory copies.  1.8
evaluator has a number of thread info on its stack and context switching
on 1.8 need to save/restore those info between stack and heap.  On the
other hand his 1.9 VM do not have to do that; context switching on 1.9
is basically a matter of pointer updates.

My understanding is that it is hence meaningless to backport fibers from
1.9 to 1.8. The slownesses of 1.8 threads are sourced from fundamental
context switching mechanism -- which is not avoidable in fibers too.