NSManagedObjectContext锁定 [英] NSManagedObjectContext Locked

查看:158
本文介绍了NSManagedObjectContext锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个线程在我的应用程序中操作。

I have two threads operating in my app.


  • 在主线程中,更新实体中的键值或获取一些行核心数据。

  • 在后台线程中,我从服务器下载数据。

更新/处理上的核心数据的次数[managedObjectContext executeFetchRequest:request error:& error]

... I get:

… I get:

#0 0x34507c5c in semaphore_wait_signal_trap()

#1 0x34507f58 in semaphore_wait_signal()

#2  0x364d573a in pthread_mutex_lock ()
#3  0x35c91a2e in -[_PFLock lock] ()
#4  0x35c91a12 in -[NSPersistentStoreCoordinator lock] ()
#5  0x35c919e8 in -[NSManagedObjectContext(_NSInternalAdditions) lockObjectStore] ()
#6  0x35c90676 in -[NSManagedObjectContext executeFetchRequest:error:] ()

NSManagedObjectContext如何锁定?我可以做什么?

How does the NSManagedObjectContext get locked? What can I do for this?

推荐答案

锁是正常操作的一部分,不是问题的根源。

The lock is part of the normal operation and is not the source of your problem.

最有可能的是,在单独的线程上管理上下文时出现问题。确保为每个线程使用不同的上下文,并确保您不在线程之间传递托管对象。请确保在尝试访问来自另一个线程的更改之前合并上下文。

Most likely, you have a problem managing the context on the separate threads. Make sure you use a different context for each thread and make sure you don't pass managed objects between the threads. Make sure you merge the contexts before trying to access changes made on one thread from another.

这篇关于NSManagedObjectContext锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆