Fix a race condition in the lock initialization.