nslock

NSRecursiveLock Deallocated

扶醉桌前 提交于 2020-01-07 05:19:07
问题 I Have an iOS app with multiple view controllers and ARC enabled. One of the view controllers has an IBOutlet for UIScrollView and UIPageControl . When that view controller is loaded this error is printed in the console: *** -[NSRecursiveLock dealloc]: lock (<NSRecursiveLock: 0xcb88cb0> '(null)') deallocated while still in use While trying to fix the problem, I created a symbolic breakpoint for the symbol _NSLockError with the module set to Foundation. Now Xcode breaks with breakpoint 1.1 on

How to lock an NSLock on a specific thread

无人久伴 提交于 2019-12-21 12:27:23
问题 I have a property @property NSLock *myLock And I want to write two methods: - (void) lock and - (void) unlock These methods lock and unlock myLock respectively and they need to do this regardless of what thread or queue called them. For instance, thread A might have called lock but queue B might be the one calling unlock . Both of these methods should work appropriately without reporting that I am trying to unlock a lock from a different thread/queue that locked it. Additionally, they need to

Object-C 多线程中锁的使用-NSLock

旧街凉风 提交于 2019-12-06 00:15:51
一、使用 synchronized 方式 // 线程 1 dispatch_async ( dispatch_get_global_queue ( DISPATCH_QUEUE_PRIORITY_DEFAULT , 0 ), ^{ @synchronized ( _myLockObj ){ [obj1 method1 ]; sleep ( 30 ); } @synchronized (obj1){ } }); // 线程 2 dispatch_async ( dispatch_get_global_queue ( DISPATCH_QUEUE_PRIORITY_DEFAULT , 0 ), ^{ sleep ( 1 ); @synchronized ( _myLockObj ){ [obj1 method2 ]; } }); } 这样,就会起到锁的作用,线程2会等待线程1执行完成 @synchronized (obj){ }块后,在执行。从而起到锁的作用。 2.使用 NSLock 方式 先贴一个例子: 1. TestObj.h @interface TestObj : NSObject - ( void )method1; - ( void )method2; @end 2. TestObj.m #import "TestObj.h" @implementation TestObj

Multi-Threading question in Objective-C 2.0

旧巷老猫 提交于 2019-12-04 14:28:16
问题 I have my main application delegate which contains a method that returns an object. This application delegate runs on the main thread. I also have a NSOperation that gets run on a different thread. As well as wanting to be able to call my app delegate method on my main thread sometimes, I also need to call it from my NSOperation thread to get the object that it returns. My first question is, if I call this from my other thread... id newObject = [[[UIApplication sharedApplication] delegate]

How to utilize NSLock to prevent a function from firing twice?

非 Y 不嫁゛ 提交于 2019-12-04 07:06:05
I current have a set of asynchronous functions that are both called in the viewDidLoad() . At the end of each function is a bool that is set from false to true upon completion of the function. There is also a conditional statement checking both function's bools that fires a third function. This conditional statement is in both functions (that I want called when both of the two have finished). Generally: var checkOne = false var checkTwo = false func functionOne(){ //async stuff checkOne = true if checkOne == true && checkTwo == true{ functionThree()//will only run if both functionOne and

How to lock an NSLock on a specific thread

我的未来我决定 提交于 2019-12-04 06:00:35
I have a property @property NSLock *myLock And I want to write two methods: - (void) lock and - (void) unlock These methods lock and unlock myLock respectively and they need to do this regardless of what thread or queue called them. For instance, thread A might have called lock but queue B might be the one calling unlock . Both of these methods should work appropriately without reporting that I am trying to unlock a lock from a different thread/queue that locked it. Additionally, they need to do this synchronously. It is rare anymore that NSLock is the right tool for the job. There much better

Multi-Threading question in Objective-C 2.0

左心房为你撑大大i 提交于 2019-12-03 09:54:13
I have my main application delegate which contains a method that returns an object. This application delegate runs on the main thread. I also have a NSOperation that gets run on a different thread. As well as wanting to be able to call my app delegate method on my main thread sometimes, I also need to call it from my NSOperation thread to get the object that it returns. My first question is, if I call this from my other thread... id newObject = [[[UIApplication sharedApplication] delegate] myMethod]; ... will that method be processed on the same thread as the NSOperation, or will it be the

How to utilize NSLock to prevent a function from firing twice?

孤者浪人 提交于 2019-11-30 05:18:27
问题 I current have a set of asynchronous functions that are both called in the viewDidLoad() . At the end of each function is a bool that is set from false to true upon completion of the function. There is also a conditional statement checking both function's bools that fires a third function. This conditional statement is in both functions (that I want called when both of the two have finished). Generally: var checkOne = false var checkTwo = false func functionOne(){ //async stuff checkOne =

Cocoa thread synchronisation when using [ALAssetsLibrary enumerateGroupsWithTypes:]

…衆ロ難τιáo~ 提交于 2019-11-28 21:37:53
I have recently, like a few people, discovered that [ALAssetsLibrary enumerateGroupsWithTypes] likes to run its blocks on another thread. What a shame that Apple didn't document that :-) In my current circumstance I need to wait for the enumeration to complete, before the main thread returns any results. I clearly need some sort of thread synchronisation. I've read about NSLock & NSConditionLock, but nothing yet seems to fit the requirement of 'signal a blocked thread that this worker thread has completed'. It seems like a simple enough need - can anyone point me in the right direction? Your

Cocoa thread synchronisation when using [ALAssetsLibrary enumerateGroupsWithTypes:]

血红的双手。 提交于 2019-11-27 14:03:18
问题 I have recently, like a few people, discovered that [ALAssetsLibrary enumerateGroupsWithTypes] likes to run its blocks on another thread. What a shame that Apple didn't document that :-) In my current circumstance I need to wait for the enumeration to complete, before the main thread returns any results. I clearly need some sort of thread synchronisation. I've read about NSLock & NSConditionLock, but nothing yet seems to fit the requirement of 'signal a blocked thread that this worker thread