On Thu, Oct 15, 2009 at 9:51 AM, Chris Wailes <chris.wailes / gmail.com> wrote:
> What I'm creating is a job queue. A thread from a central thread pool
> grabs a job and then executes it. In very special circumstances, when a
> job on the queue is waiting for a response from another job on the
> queue, the job needs to pause and be put back onto the queue to wait for
> a value.
>
> With fibers I could call Fiber.yield() and that would kick control back
> out to the thread who would push it back onto the queue. The problem
> with your solution, in this particular case, is that the fiber couldn't
> be resumed from where it last exited and would have to be re-ran from
> the beginning.

Ah, I got that you needed it to get picked up by a different thread
then the creating thread and paused and resumed once it was running, I
missed that you needed to have one thread pause it once it was started
and another resume it.

I'm pretty sure there is no easy way to do this in existing Ruby
implementations save maybe Rubinius; the problem seems approximately
equivalent to implementing serializable continuations. IIRC Rubinius
plans to have serializable continuations (don't know if they are
implemented yet), so it might be doable under Rubinius (if you have
serializable continuations, you achieve what you want by serializing
the continuation where you would pause the Fiber, then passing the
serialized continuation back to the queue, where a later thread picks
it up and reinstantiates it.)