Multithreaded Applications in Ruby : join « Threads « Ruby






Multithreaded Applications in Ruby



def func1
     i=0
     while i<=3
     puts "func1 at: #{Time.now}"
     sleep(2)
     i=i+1
     end
end
def func2
     j=0
     while j<=3
     puts "func2 at: #{Time.now}"
     sleep(1)
     j=j+1
     end
end
puts "Started At #{Time.now}"
t1=Thread.new{func1()}
t2=Thread.new{func2()}
t1.join
t2.join
puts "End at #{Time.now}"

 








Related examples in the same category

1.each thread is given only one second to execute:
2.Join threads
3.Join two threads
4.rescue the exception at the time the threads are joined.
5.Join a thread after sleeping