Fix race condition by adding a mutex