Lock when adding specs during Gem installation.

When installing Gems in a multi-threaded environment (e.g. Bundler) the
installer would try to run the following code:

    Gem::Specification.add_spec spec unless Gem::Specification.include? spec

This code is not thread-safe for two reasons:

1. Gem::Specification.add_spec modifies a global state
2. Gem::Specification.include? performs a read operation on a global state
   _while_ it might be modified

Working around this can be done in two ways:

1. Add locks to Gem::Specification where needed
2. Add locks in Gem::Installer where needed

The first option would require a lock around most class methods and possibly
other methods. As a result I've decided to, for now, go with option 2. Skimming
through the Installer class this appears to be the only place where a global
state is modified.

The issue that led to this commit is #982 which contains more details about the
problem.