make queue flush atomic