Add a mutex to ensure no concurrent writes.