K
Karan Rajput
Hi,
I am not enough efficient in Threads.
Here is the problem.
i = 1
while(i < 100)
t = Thread.new do
echo(i)
end
t.join if (i % 5 == 0)
i = i + 1
end
def echo(num)
puts num
end
I get output sometimes as,
1
2
3
5
5 ==> 5 is getting duplicated whereas 4 is dropped. I feel its race
condition for variable.
6.... and so on.
This error occurred for any random number.
Sometime i get the correct output.
Can anybody suggest what will be solution to avoid any such problem.
Will replacement of Thread with Process will solve problem?
I am hoping solution in Threads only if its possible.
Thanks in Advance.
I am not enough efficient in Threads.
Here is the problem.
i = 1
while(i < 100)
t = Thread.new do
echo(i)
end
t.join if (i % 5 == 0)
i = i + 1
end
def echo(num)
puts num
end
I get output sometimes as,
1
2
3
5
5 ==> 5 is getting duplicated whereas 4 is dropped. I feel its race
condition for variable.
6.... and so on.
This error occurred for any random number.
Sometime i get the correct output.
Can anybody suggest what will be solution to avoid any such problem.
Will replacement of Thread with Process will solve problem?
I am hoping solution in Threads only if its possible.
Thanks in Advance.