Avoid race conditions in SpinLock.

Use a ReentrantReadWriteLock to avoid a race condition in the SpinLock
class. Fixes issue #2.