Fixed a race condition while updating pids.