ref: 391dd56eacb294363687cb73b80c9d8ef6dc650d
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