ref: 06f3e2952573fc39657726c6d84e5e3b33939abc
dir: /Test_Multi_Threading.rb/
require 'thread' # Define a method that performs some asynchronous task def async_task(name) puts "Starting #{name}" # Simulate some work sleep(rand(5)) puts "#{name} completed" end # Create multiple threads for asynchronous execution threads = [] threads << Thread.new { async_task('Task 1') } threads << Thread.new { async_task('Task 2') } threads << Thread.new { async_task('Task 3') } # Wait for all threads to complete threads.each(&:join) puts "All tasks completed" def Test for i in 0..10 do puts i sleep(rand(0.1..1.0)); end end t1 = Thread.new{Test()} t2 = Thread.new{Test()} puts 'moz' t1.join t2.join