Skip to content

Instantly share code, notes, and snippets.

@thedarkone
Created September 7, 2012 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedarkone/3668788 to your computer and use it in GitHub Desktop.
Save thedarkone/3668788 to your computer and use it in GitHub Desktop.
require 'thread'
bignum = (2 ** (0.size * 8))
start = 0
class H < Hash
def [](key)
super if key.kind_of?(Symbol)
end
def []=(key, value)
super if key.kind_of?(Symbol)
end
end
h = H.new
h[:a] = start
iterations = 100_000
thread_count = 100
threads = (1..thread_count).map do
Thread.new do
iterations.times do
h[:a] += 1 # 1
h[:a] += 1 # 2
h[:a] += 1 # 3
h[:a] += 1 # 4
h[:a] += 1 # 5
h[:a] += 1 # 6
h[:a] += 1 # 7
h[:a] += 1 # 8
h[:a] += 1 # 9
h[:a] += 1 # 10
end
end
end
threads.map(&:join)
puts "h[:a] => #{h[:a]}, should be: #{(thread_count * iterations * 10)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment