Setting thresholds for pest control: how does pest density affect resource viability?