首页 > 代码库 > ruby-thread/process

ruby-thread/process

thread

a = 1threads = []mutex = Mutex.new5.times do  threads << Thread.new do    1000.times do      mutex.synchronize{        a = a + 1      }    end  endendthreads.each{ |t| t.exit }  # t.killthreads.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	endend#puts "I have child"process.each{ |pid| Process.wait(pid)}

 

ruby-thread/process