Lock when adding specs during Gem installation.

Related issue: https://github.com/rubygems/rubygems/issues/982