An NSLock object is used to coordinate the operation of multiple threads of execution within the same application. An NSLock object can be used to mediate access to an application’s global data or to protect a critical section of code, allowing it to run atomically.
Questions tagged [nslock]
42 questions
0
votes
1 answer
How to use NSLock safely in Swift
I'm new to Swift. I saw some NSLock examples online and they are all like below:
let lock = NSLock()
func test() {
// some code
}
func run() {
lock.lock()
test()
lock.unlock()
}
If the test function crashes, the lock will never be…

Bruce L
- 41
- 2
0
votes
2 answers
Usage of NSLock in property setter
Let's say, there is a variable that I want to make thread safe. One of the most common ways to do this:
var value: A {
get { return queue.sync { self._value } }
set { queue.sync { self._value = newValue } }
}
However, this property is not…

V.V.V
- 235
- 1
- 13
0
votes
1 answer
waiting on a locked NSLock until tryLock succeeds
I have a class with 2 methods, the first one makes an animation for a second and the second performs some task.
This class is being called from a second class to perform those two operations consecutively but I want to enforce a lock so that the…

Edward Ashak
- 2,411
- 2
- 23
- 38
0
votes
0 answers
How to use NSLock in a function?
Is this the correct method to prevent more than one thread to access the function MyTaskF?
.h file:
@interface MyInterface : NSObject {
//... some other stuff here
}
.m file:
static NSLock *mytaskMutex;
static MyInterface…

smartie1
- 1
- 1
0
votes
1 answer
Protecting read/write access to NSManaged object array
I have an array of NSManagedObjects, which is shared by several fragments, some on main queue some inside callback closures. Sometimes while I am clearing this array , other part of code tries to access it to read and show the data on UI and as it…

vishal dharankar
- 7,536
- 7
- 57
- 93
0
votes
4 answers
Even though after lock the threads get crashed <__NSArrayM: 0x7f881a6b1900> was mutated while being enumerated?
This my code ,i am removing multiple values on my condition
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
PhotoCan *cell=[collectionView cellForItemAtIndexPath:indexPath];
…

Kishore Kumar
- 4,265
- 3
- 26
- 47
0
votes
1 answer
My program is executing out of order, I'm assuming because of some threads finishing before another. NSLock, GDC, suggestions?
From a programming standpoint, because of the way the code is written I can't necessarily work around this.
Basically, in pseudocode:
if NSUserDefaults' stored token exists{
setFlag(token)
// setFlag will make an API call with the token and…

ksm18
- 93
- 8
0
votes
1 answer
Multi-thread daata access issue, @synchronized & serial queue
As you may have experienced, access none-thread safe variables is a big headache. For iOS one simple solution is to use keyword @synchronized, which will add NSLock to insure the data can be accessed by unique one thread, the disadvantage is as…

jianhua
- 1,011
- 1
- 12
- 28
0
votes
2 answers
NSLock, number of threads waiting
I'm developing an iOS app and need to implement a solution for a problem for which I need to know how many threads are waiting for locking the same NSLock object.
In Java I have the class ReentrantLock, with the method getQueueLength, which "Returns…

Massimo
- 3,436
- 4
- 40
- 68
0
votes
2 answers
NSRecursiveLock Deallocated
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…

user2563039
- 1,418
- 2
- 11
- 15
0
votes
2 answers
Control access to webservice method from multiple UIViewControllers
I have an iOS app with a tabbar and 3 different UIViewControllers, one for each tab. The app uses SudzC to interface with a C# .NET webservice to pull data from a database.
There is one webservice method that is called from all three view…

Andrew Wilcockson
- 133
- 9
0
votes
3 answers
How to lock code execution in iOS application
Problem Description
I have a function StdString ShowLockScreen() in this function I call activateViewController function which shows some UI where user must enter PIN, just after calling activateViewController function I want to lock all processes…

Viktor Apoyan
- 10,655
- 22
- 85
- 147