The Computer Language
Benchmarks Game

thread-ring Ruby #2 program

source code

# The Computer Language Benchmarks Game
# http://benchmarksgame.alioth.debian.org
#
# contributed by Serhiy Boiko


#require 'thread'
THREAD_NUM = 503
number = ARGV.first.to_i

threads = []
for i in 1..THREAD_NUM
   threads << Thread.new(i) do |thr_num|
      while true
         Thread.stop
         if number > 0
            number -= 1
         else
            puts thr_num
            exit 0
         end
      end
   end
end

prev_thread = threads.last
while true
   for thread in threads
      Thread.pass until prev_thread.stop?
      thread.run
      prev_thread = thread
   end
end
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]


Sun, 12 Feb 2017 20:54:57 GMT

COMMAND LINE:
/usr/local/src/ruby/bin/ruby -W0 threadring.yarv-2.yarv 50000000

PROGRAM OUTPUT:
292