Questions tagged [nslock]

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.

42 questions
2
votes
1 answer

How can I set a breakpoint on _NSLockError()

I am trying to debug multiple threads. *** -[NSLock lock]: deadlock ( '(null)') *** Break on _NSLockError() to debug. How can I debug this?
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
2
votes
3 answers

Using NSLocks as atomic or non atomic properties?

Should i declare NSLock as atomic, or it's just a waste of time and the lock itself should be non atomic?
Zbun
  • 4,875
  • 4
  • 19
  • 28
2
votes
1 answer

iOS App freezing with NSConditionLock

I'm having this wierd problem with the app freezing at a certain point. I'm guessing its got to do with how I'm using NSConditionLock. Theres a library I have been given to use, which consists of a series of survey questions, but it works in such a…
Akash Malhotra
  • 1,106
  • 1
  • 17
  • 30
2
votes
0 answers

Best design pattern for background threads for populating NSTableView

I am trying to create background threads for fetching Core Data in order to populate an NSOutlineView. The operation can take a few seconds so I was wanting to put the operation in a background thread and display the UI to the user as shown below.…
Duncan Groenewald
  • 8,496
  • 6
  • 41
  • 76
2
votes
3 answers

Multi-Threading question in Objective-C 2.0

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…
Michael Waterfall
  • 20,497
  • 27
  • 111
  • 168
2
votes
2 answers

Make Queue thread-safe

I have a camera session and i am taking images from the buffer: -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { CVPixelBufferRef…
1
vote
0 answers

Accessing different indexes of array race condition

If I have a three-element array and multiple threads attempting to access those values. Is there a race condition if I protect each of the three indexes with a separate lock? In other words, if I know that no two threads will access the same index…
1
vote
1 answer

Does DispatchQueue also Lock the resources used inside it?

class Factory { var localSharedResource var localQueue = DispatchQueue(label: "localQueue") let threadLock = NSLock() func modify(){ localQueue.async { self.threadLock.lock() localSharedResource = "a change is made here" …
1
vote
1 answer

How to elegantly lock when all code is on the main thread (looking for alternative to NSLock)

I have a situation where I have to wait for a UIKit animation to finish and I am using a completion block to execute the relevant finalising code. Now I have realised that I can trigger a race condition, which introduces errors, when I call the…
1
vote
1 answer

ios creating a write lock based on a key

I know about using dispatch_barrier_async to lock a given resource, but in my case it isn't a good candidate because I am not modifying a shared data structure, rather a resource on disk and don't want to block the whole queue, rather just a given…
Avba
  • 14,822
  • 20
  • 92
  • 192
1
vote
2 answers

How to make particular part of function wait in iOS

I'm trying to do a share operation where I call a function with async block but in my next if statement I need to get the value which is completed in the block to continue. This is my code which will highlight more detail. I heard about NSLock and…
Francis F
  • 3,157
  • 3
  • 41
  • 79
1
vote
2 answers

Should an NSLock instance be "global"?

Should I make a single NSLock instance in the application delegate, to be used by all classes? Or is it advisable to have each class instantiate its own NSLock instance as needed? Would the locking work in the second case, if I, for example, had…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
1
vote
1 answer

@synchronized to lock iVar and/or property?

Possible Duplicate: What does @synchronized() do? I have a question about what @synchronized really does and what would be best for my application. I have an NSMutableArray that I will be mutating in background threads and accessing in foreground…
RileyE
  • 10,874
  • 13
  • 63
  • 106
0
votes
1 answer

Block HTTP Requests or make them run synchron

I have two HTTP-Requests and i have to execute them in the ordert that I execute the first one, wait till its done and then execute the second one. I used to do this with a loop and a variable inside the call and only if the variable inside the call…
Pjaks
  • 251
  • 1
  • 11
0
votes
0 answers

Swift: Struct thread safe array crashing with NSLock

I'm trying to implement a thread-safe array component in the most efficient and safe way, backed by unit tests. So far, I would prefer a struct array, to keep a value type and not a reference type. But when I run the test below, I still have random…
Xys
  • 8,486
  • 2
  • 38
  • 56