On Sun, Oct 6, 2013 at 11:34 AM, Raja gopalan <lists / ruby-forum.com> wrote:
> hi  Robert Klemme,
>
> I understood what you meant,when a thread takes longer time OS
> automatically spawns second thread.

I did not say that at all!  The OS does not just spawn threads if
something takes longer.  The user is responsible for spawning threads.
 The OS only schedules them according to criteria implemented in its
scheduler.

> But my requirement was as I stated
> above comment to Joel Pearson. So If Ruby spawns a new thread according
> to my wish,that would be useful for me.

To repeat myself: it's the decision of the scheduler (either OS or
Ruby) when it will execute which thread.  Your two threads will be
perfectly executed in parallel as I have demonstrated with my last
posting.  Your tests just did not do enough to trigger alternation.
And if they don't do much then it's probably also not an issue to have
them executed sequentially.

If you have requirements that certain things need to happen in order
you need to properly synchronize threads anyway.  There's monitors,
condition variables, blocking queues etc.

Cheers

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/