Prevent theoretical race conditions

They're theoretical because at the moment we're only supporting MRI,
which uses a GIL which means it's impossible for these data structures
to be simultaneously accessed.

However in the future we will support Rubinius, which has no GIL and may
need this synchronisation.