For example here is the .m:
-(void)counterPlusOne
{
[_counter plusOne];
}
-(void)counterMinusOne
{
[_counter minusOne];
}
There two methods may be called together, or one being called, another will be called as well. For example, if the userCallcountPlusOne, the _counter's plusOne method, may be a lots of thing first. But while the calculating in counterPlusOne, the counterMinusOne may also being called. So, if these two thing go together, the _counter's valuables may be messed up. How can I avoid that? Thanks.
try use
@synchronizedif you can't find better solution, because lock in code is bad in definition