Revisions
-
wycats revised this gist
Oct 7, 2011 . No changes.There are no files selected for viewing
-
wycats revised this gist
Oct 7, 2011 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,10 @@ def incr sleep end def total $mutex.synchronize { return $total } end def fib(n) incr if (0..1).include? n fib(n-1) + fib(n-2) if n > 1 @@ -19,6 +23,6 @@ def fib(n) threads << Thread.new { fib(30) } end sleep 0.5 until total == 1000 system "ps -orss #{Process.pid}" -
wycats revised this gist
Oct 7, 2011 . 1 changed file with 12 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,15 @@ require "thread" $mutex = Mutex.new $total = 0 def incr $mutex.synchronize { $total += 1 } sleep end def fib(n) incr if (0..1).include? n fib(n-1) + fib(n-2) if n > 1 end @@ -9,6 +19,6 @@ def fib(n) threads << Thread.new { fib(30) } end sleep 0.5 until $total == 1000 system "ps -orss #{Process.pid}" -
wycats created this gist
Oct 7, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ def fib(n) sleep if (0..1).include? n fib(n-1) + fib(n-2) if n > 1 end threads = [] 1000.times do threads << Thread.new { fib(30) } end sleep 30 system "ps -orss #{Process.pid}"