ruby-thread/process

thread

a = 1
threads = []
mutex = Mutex.new

5.times do
  threads << Thread.new do
    1000.times do
      mutex.synchronize{
        a = a + 1
      }
    end
  end
end

threads.each{ |t| t.exit }  # t.kill
threads.each{ |t| t.join(10) }
puts a

process基于unix

process = []

5.times do
	process << Process.fork do
		puts "Chile do hard work. #{Process.pid}:#{Process.ppid}"
		sleep 10
	end
end

#puts "I have child"
process.each{ |pid| Process.wait(pid)}
原文地址:https://www.cnblogs.com/lly-lly/p/5887511.html