-
-
Save kookster/af3c91a9683ffbcd4eef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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