use atomic counter instead of chan