码迷,mamicode.com
首页 > 其他好文 > 详细

ruby-thread/process

时间:2016-09-20 10:09:15      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

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)}

 

ruby-thread/process

标签:

原文地址:http://www.cnblogs.com/lly-001/p/5887511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!