Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created May 15, 2015 18:21
Show Gist options
  • Save yorickpeterse/edbad48ce3d152afe234 to your computer and use it in GitHub Desktop.
Save yorickpeterse/edbad48ce3d152afe234 to your computer and use it in GitHub Desktop.
require 'openssl'
require 'thread'
puts "rubysl-openssl: #{RubySL::OpenSSL::VERSION}"
puts "rubysl-digest: #{RubySL::Digest::VERSION}"
Thread.abort_on_exception = true
input = 'the cake is possibly a lie'
digest = Digest::SHA256.new
digest.update(input)
expected = digest.hexdigest
output = Queue.new
puts 'Starting threads...'
threads = 10.times.map do
Thread.new do
loop do
digest = Digest::SHA256.new
digest.update(input)
got = digest.hexdigest
output << got unless got == expected
end
end
end
got = output.pop
threads.each(&:kill)
raise "Expected digest #{got.inspect} to equal #{expected.inspect}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment