Hi Raja,

Most ruby versions doesn't support native threads. (If you need them I
think the options are jruby and rubinius).
So you shouldn't expect this specific behaviour you described.
Threads is all about "time slices".
What is wrong if the "hello" thread is able to print 10x "hello" in
its "time slice" before the control is yielded to the another thread?

To have a slightly different behaviour, test putting a sleep inside
each thread so that the thread "sleeps" and pass the control to the
other thread.

@i=0;@j=0
def hi
  hello
  while(@i<10)
    puts 'hi'
    @i+=1
    sleep 0.1
  end
end
def hello
Thread.new do
  while(@j<10)
    puts 'hello'
    @j+=1
    sleep 0.1
  end
end
end
hi #function call

Best regards,
Abinoam Jr.

On Fri, Oct 4, 2013 at 7:19 AM, Raja gopalan <lists / ruby-forum.com> wrote:
> hi
> please consider the below program,
>
> @i=0;@j=0
> def hi
>   hello
>   while(@i<10)
>     puts 'hi'
>     @i+=1
>   end
> end
> def hello
> Thread.new do
>   while(@j<10)
>     puts 'hello'
>     @j+=1
>   end
> end
> end
> hi #function call
>
> Output
>
> hello
> hello
> hello
> hello
> hello
> hello
> hello
> hello
> hello
> hello
> hi
> hi
> hi
> hi
> hi
> hi
> hi
> hi
> hi
> hi
>
> Now my question is I introduce the thread inside the hello function but
> it hasn't run my file parallelly instead execution goes sequentially.
> What to do to run this both the function parallelly ? The output might
> be like below
>
> hello
> hi
> hello
> hi
> ...
> ...
>
> --
> Posted via http://www.ruby-forum.com/.