Fixed race condition by introducing a mutex with LockIfPossible capability.