The Computer Language
Benchmarks Game

thread-ring Ruby JRuby program

source code

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

require "thread"

THREAD_COUNT = 503

class Receiver
  @next
  @mailbox

  def initialize(name)
    @name = name
    @mailbox = Queue.new
  end

  def next=(n)
    @next = n
  end

  def put(msg)
    @mailbox.push(msg)
  end

  def messageloop
    while true
      hopsRemaining = @mailbox.pop
      if(hopsRemaining == 0)
        print @name, "\n"
        exit(0)
      end
      @next.put(hopsRemaining - 1)
    end
  end
end

##########
#  Main  #
##########
receivers = []
for i in 0..THREAD_COUNT-1
  receivers[i] = Receiver.new(i+1)
  if(i > 0)
    receivers[i-1].next = receivers[i]
  end
end
#close the ring
receivers[THREAD_COUNT-1].next = receivers[0]

# start the threads
for i in 0..THREAD_COUNT-1
  Thread.start(i){|k| receivers[k].messageloop}
end

receivers[0].put(ARGV[0].to_i)

sleep

    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
jruby 9.1.16.0 (2.3.3) 2018-02-21 8f3f95a Java HotSpot(TM) 64-Bit Server VM 10+46 on 10+46 +jit [linux-x86_64]


Thu, 22 Mar 2018 03:52:35 GMT

MAKE:
mv threadring.jruby threadring.rb

0.01s to complete and log all make actions

COMMAND LINE:
/opt/src/jruby-9.1.16.0/bin/jruby -Xcompile.fastest=true -Xcompile.invokedynamic=true -J-server -J-Xmn512m -J-Xms2048m -J-Xmx2048m threadring.rb 50000000

PROGRAM OUTPUT:
292