同步 NSMutableArray 以实现线程安全?

Synchronizing NSMutableArray for Thread Security ?(同步 NSMutableArray 以实现线程安全?)

本文介绍了同步 NSMutableArray 以实现线程安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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];
}

这篇关于同步 NSMutableArray 以实现线程安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:同步 NSMutableArray 以实现线程安全?

基础教程推荐