rubygems/rubygems — pull request #737 by Who828 (2013-12-10 05:20:36+00:00)
Title: Use file locks to ensure safety when being installed in a parallel

Hey folks,

I have used file locks in remote fetcher to ensure that no two process or threads can write/read the same file at the same time. Looking at the remote fetcher code, it's designed to be used as a singleton, thus its better to take this precaution.

The performance impact should be minimal because the file locks are local to that specific file, so the gems(different names/versions) can still be downloaded and installed in parallel. Just that in case two gems with the same name/version and same path are downloaded for some reason. This lock will prevent such situation.

Also, after checking missing/flock.c in ruby even Windows implements File::LOCK_EX and File::LOCK_UN. so this should be good to go on multiple platforms.