Questions tagged [nscondition]
20 questions
13
votes
3 answers
EAAcessory errors while closing session with iOS 6.0 GM
There is a MFI device that is connected to iPhone 4S (6.0 GM) or to iPad (6.0 GM) via Bluetooth (2.1 + EDR). The project was built on Xcode 4.5 GM. When the app gets EAAccessoryDidDisconnectNotification it will send message [_eaSessionController…

Yauheni Shauchenka
- 753
- 1
- 9
- 26
4
votes
3 answers
What's the difference between NSCondition and dispatch_semaphore in iOS except their API?
They both use a counter and use a lock to protect the increment and decrement of the counter, and when the counter is less than zero, the thread waits. It seems to me that they are the same except for their api.

N.Lee
- 986
- 7
- 13
3
votes
2 answers
iOS - Objective-C - How to stop NSThread, when it's waiting?
I have an nsthread, a while loop within this one. It's getting objects from a "thread-safe" queue in the main method. When I leave the UIViewController, which contains this nsthread object, I call the nsthread cancel method, but it doesn't stop,…

Gilberto Uno
- 33
- 1
- 4
3
votes
1 answer
NSCondition, what if no lock when call signal?
From this Apple's document about NSCondition, the usage of NSCondition should be:
Thead 1:
[cocoaCondition lock];
while (timeToDoWork <= 0)
[cocoaCondition wait];
timeToDoWork--;
// Do real work here.
[cocoaCondition unlock];
Thread…

Albert Zhang
- 757
- 1
- 8
- 19
3
votes
1 answer
NSCondition - multiple threads
i know that the following is how you are supposed to use NSCondition:
method 1:
[cocoaCondition lock];
while (someConditionIsTrue)
[cocoaCondition wait];
// Do real work here.
[cocoaCondition unlock];
method 2:
[cocoaCondition…

David Ben Ari
- 2,259
- 3
- 21
- 40
2
votes
1 answer
Waiting on asynchronous methods using NSCondition
I am downloading four plist files asynchronously over the internet. I need to wait until all four files are downloaded, until I either on the first run, push a UIViewController, or on all subsequent runs, refresh the data, and reload all my…

Brandon Mcq
- 575
- 2
- 10
- 24
2
votes
1 answer
How do I wake up a thread at a specified time in objective-c
I'm writing an ssh wrapper in objective-c, I'm trying to implement a maxTime a command should take to execute. The way I implement it is:
Main Thread:
calculate timeout
create asyncThread (GCD queue) to execute command and parse the returned…

whisperstream
- 1,897
- 3
- 20
- 25
1
vote
2 answers
NSCondition: Recursive Locking?
I am working on creating a blocking queue, accessed by about 10 worker threads simultaneously. The basic implementation of the queue is like this:
-(void) enqueue:(__strong id)value
{
[_mutex lock];
while ([self size] == _maxSize) {
…

Richard J. Ross III
- 55,009
- 24
- 135
- 201
1
vote
1 answer
Thread-safe access to a datasource during a tableView update
My app uses a tableView with a data source that can be updated asynchronously by multiple threads.
When the data source is changed, the tableView is updated, not reloaded, using
tableView.performBatchUpdates({
tableView.deleteRows(at:…

Reinhard Männer
- 14,022
- 5
- 54
- 116
1
vote
1 answer
Unlocking a thread using NSCondition (Objective-C)
I am using Objective-C and was trying to work with threads which need to talk to each other.
The code is as follows:
-(id) init
{
self = [super init];
if (self) {
_event = [[MyTestClass alloc]init]; //MyTestClass has a property of…

Vineeth v.r
- 40
- 4
1
vote
2 answers
Pause Main thread until background thread retrieves user input
In my main starting thread I need to pause the code and start a new thread and wait until I get user input. Then Id like to discard the new thread made and go back to where the main thread left off. But whats happening is that the new thread is…

4GetFullOf
- 1,738
- 4
- 22
- 47
1
vote
0 answers
Return result of asynchronous call to the method the called it
I'm writing a standard NSURLConnection class for the App I'm working on right now which I will hopefully be able to use subsequent apps as well.
The idea is to able to pass a URL and a parameters array to a method in this class that will start the…

centreee
- 137
- 2
- 8
0
votes
0 answers
Swift How to wait until a specific condition is met
I've looked through just about every question on this topic I could find but I've had little success. I need to run a function on an array of actors conforming to a specific actor protocol. Because these are actors, I need an async call. But I also…

Tiny Tim
- 207
- 1
- 6
0
votes
1 answer
Need to wait on completion of setFocusModeLockedWithLensPosition - Semaphore? Atomic? NSCondition?
I’ve not had much experience with semaphores, nor with blocks. I’ve seen various suggestions for how to turn an asynchronous call into a synchronous one. In this case I just want to wait to be sure the lens of the iPhone has changed focus before…

user938797
- 167
- 3
- 15
0
votes
1 answer
NSCondtion with multiple threads
method1:
- (void) method1
{
[_condition lock];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
//Fetach data from remote, when finished call method2
[self…

Kevin Liu
- 3
- 4