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?
I can not tell this better than Apple. Take a look at section “Using the @synchronized Directive”. http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/ThreadSafety/ThreadSafety.html
Double-check that you are passing the same synchronization/lock object into synchronized so threads will not access the same section.