Possible Duplicate:
How does @synchronized lock/unlock in Objective-C?
I have an application that creates several objects. Each of these objects is essentially running in a different thread, and operating on an NSMutableArray
which is part of a separate class. There are several different methods in this class that enumerate and mutate the array, and as expected the multiple threads do not work well with this. I have tried surrounding all the method bodies in @synchronized
blocks, as I read somewhere that that would lock the methods to one thread at a time, but it doesn't seem to have helped. How can I make sure that only one thread is accessing these methods at a time?