@property (atomic, retain) NSArray *array;
I don’t override a setter and a getter of the array. I could use @synchronized(array){} or @synchronized(self.array){}. As I knows all cases are correct, am I right?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As you’ve phrased the question, both statements are equivalent as a matter of concurrency safety strategy.
Depending on the scale and how far you have completed work on your project, you may wish to consider an alternative strategy for thread-safety altogether.
Recently, Apple has made a point of recommending thread-safety-by-serialization rather than traditional blocking. In short, as contention increases, serialized access is far more efficient than blocking with @synchronize.
Rather than synchronize, consider setting up a GCD serial queue and queuing up access to resources shared across threads.