Use atomic bool for thread closure