同步 NSMutableArray 以实现线程安全?线程、安全、NSMutableArray

2023-09-07 16:10:46 作者:留点小胡须

I have a Threaded application, in which there is a NSMutableArray, which contains the NSManagedObjects, Now i want my array to be accessed once at a time by any Thread. So how do i synchronize that array, or may be put locking mechanism on it.

Thanks in Advance ...

解决方案 什么是线程安全和线程不安全

You could wrap every access to the class with something like the following:

@synchronized(myArray) {
  [myArray doSomething];
}