Skip to content

Instantly share code, notes, and snippets.

@ericbeland
Created May 16, 2014 19:43
Show Gist options
  • Save ericbeland/5204d0fa31fcce4b44ea to your computer and use it in GitHub Desktop.
Save ericbeland/5204d0fa31fcce4b44ea to your computer and use it in GitHub Desktop.
puts "---Starting run---"
threads = []
@mutex = Mutex.new
thread1_ids = []
thread2_ids = []
o = nil
a = nil
threads << Thread.new do
50000.times do
@mutex.synchronize { a = Object.new }
thread1_ids << a.object_id
end
end
threads << Thread.new do
50000.times do
@mutex.synchronize { o = Object.new }
thread2_ids << o.object_id
end
end
threads.each {|th| th.join}
thread1_ids.sort!
thread2_ids.sort!
dups = thread1_ids & thread2_ids
puts "Duplicates: #{dups.inspect}"
puts "Total dups: #{dups.length}"
puts "---DONE---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment