Multithreads without synchronization : Synchronization « Threads « Ruby






Multithreads without synchronization

x = 0
t1 = Thread.new do
  1.upto(1000) do
    x = x + 1
  end
end

t2 = Thread.new do
  1.upto(1000) do
    x = x + 1
  end
end

t1.join
t2.join
puts x

 








Related examples in the same category

1.Controlling the Thread Scheduler
2.This is easy using monitors.
3.Use monitor to lock
4.make specific objects into monitors.
5.Synchronizing Access to an Object