Created
October 17, 2013 00:17
-
-
Save m-ueno/7017248 to your computer and use it in GitHub Desktop.
http://www.jstorimer.com/blogs/workingwithcode/8085491-nobody-understands-the-gil Appending to arrays is not thread-safe
Very few things are implicitly thread-safe in Ruby. For example, appending to arrays:
This file contains 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
array = [] | |
5.times.map do | |
Thread.new do | |
1000.times do | |
array << nil | |
end | |
end | |
end.each(&:join) | |
puts array.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment