use of Thread.stop, Thread.pass, and Thread.run: : pass « Threads « Ruby






use of Thread.stop, Thread.pass, and Thread.run:


threadA = Thread.new do
    i = 0
    loop do
        puts "Thread A: #{i += 1}"
        sleep 0.5
        Thread.pass
    end
end
threadB = Thread.new do
    i = 0
    loop do
        puts "Thread B: #{i += 1}"
        sleep 0.5
        Thread.pass
    end
end
threadC = Thread.new do
    i = 0
    loop do
        puts "Thread C: #{i += 1}"
        Thread.stop
    end
end

loop do
    sleep 0.5
    threadC.run
end

 








Related examples in the same category