Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kookster/af3c91a9683ffbcd4eef to your computer and use it in GitHub Desktop.
Save kookster/af3c91a9683ffbcd4eef to your computer and use it in GitHub Desktop.
puts "---Starting run---"
threads = []
@mutex = Mutex.new
thread1_ids = []
thread2_ids = []
o = nil
a = nil
os = []
as = []
threads << Thread.new do
50000.times do
@mutex.synchronize { a = Object.new }
as << a
thread1_ids << a.object_id
end
end
threads << Thread.new do
50000.times do
@mutex.synchronize { o = Object.new }
os << o
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 "os:#{os.size}, as:#{as.size}"
puts "---DONE---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment