mercredi 26 mars 2014

Thread-safety for hashes in Ruby


Vote count:

0




I'm curious about thread safety for hashes in Ruby. Running the following from the console (Ruby 2.0.0-p247):



h = {}
10.times { Thread.start { 100000.times {h[0] ||= 0; h[0] += 1;} } }


returns



{0=>1000000}


which is the correct expected value.


Why does it work? Can I rely on hashes being thread-safe with this version of Ruby?



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire