Project

General

Profile

Actions

Bug #11953

closed

ThreadError in 2.3 on code that works on 2.2.4

Added by claytonflesher (Clayton Flesher) about 8 years ago. Updated over 6 years ago.


Description

This is my first bug reporting, so I'm sorry if this isn't exactly correct format. I'll update my report accordingly if pointed in the right direction.

I ran into what appears to be a bug while doing a quiz.

I've included the breaking code, the test suite and the description of the quiz as attachments to this bug report.

The following code works fine on Ruby 2.2.4.

class Prime
  def self.nth(num)
    error(num)
    primes = build_primes(num)
    primes.last
  end

  private

  def build_primes(num)
    primes = [2]
    index  = 3 
    until primes.size == num
      if example?(index, primes)
        primes << index
      end
      index += 1
    end
    primes
  end

  def error(num)
    unless num > 0
      raise ArgumentError
    end
  end

  def example?(index, primes)
    primes.each do |prime|
      if index % prime == 0
        return false
      end
    end
    true
  end
end

It raises this error in Ruby 2.3.0

ThreadError: deadlock; recursive locking
    /home/clayton/.rubies/ruby-2.3.0/lib/ruby/2.3.0/singleton.rb:140:in `synchronize'
    /home/clayton/.rubies/ruby-2.3.0/lib/ruby/2.3.0/singleton.rb:140:in `instance'
    /home/clayton/.rubies/ruby-2.3.0/lib/ruby/2.3.0/singleton.rb:142:in `block in instance'
    /home/clayton/.rubies/ruby-2.3.0/lib/ruby/2.3.0/singleton.rb:140:in `synchronize'
    /home/clayton/.rubies/ruby-2.3.0/lib/ruby/2.3.0/singleton.rb:140:in `instance'
    /home/clayton/exercism/ruby/nth-prime/nth_prime.rb:3:in `nth'
    nth_prime_test.rb:28:in `test_first'

If this is expected behavior, I'm sorry in advance for wasting your time.


Files

nth_prime.rb (528 Bytes) nth_prime.rb Breaking code claytonflesher (Clayton Flesher), 01/05/2016 06:59 PM
nth_prime_test.rb (973 Bytes) nth_prime_test.rb Tests claytonflesher (Clayton Flesher), 01/05/2016 07:00 PM
README.md (1.27 KB) README.md Quiz description claytonflesher (Clayton Flesher), 01/05/2016 07:00 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0