pids: fix a race in pid generation that causes pids to be reused immediately