rubyはマルチスレッドのプログラムを書いても、CPUは一個しか使ってくれないらしい。
GIL というもののせいらしい。。
http://ja.wikipedia.org/wiki/グローバルインタプリタロック
そこでマルチプロセスのプログラムを作ってみる
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/bin/env ruby class Test def exec t1=fork{calc} t2=fork{calc} Process.waitpid t1 Process.waitpid t2 end def calc tim=rand(10) p Process.pid.to_s+",start,"+tim.to_s sleep tim p Process.pid.to_s+",end,"+tim.to_s exit end end if __FILE__ == $0 then Test.new.exec end |