Questions tagged [nsthread]

`NSThread` is part of the Objective-C Foundation Framework and provides developers a way to create and manage threads.

An instance of NSThread controls a thread of execution. Developers can use this class when they would like to perform a series of tasks in its own thread of execution. An example is if the developer wanted to have an Objective-C method run in its own thread of execution.

Threads are useful for long-running tasks that avoid blocking the main thread of the application (where user interface and event-related tasks are handled), as well as dividing a large task into several smaller sub-tasks. This can lead to performance improvements.

In GNUStep, NSThread essentially encapsulates OpenStep threading. Each process starts with a main thread and additonal threads can be created by using NSThread. The GNUStep implementation of OpenStep was designed so that the internals of the base library do not use threading (except in the case of methods that explicitly deal with threads). This makes it possible to write applications without any sort of threading.

References

729 questions
1
vote
1 answer

Objective-C: [NSObject performSelector: onThread...] does not get called if the thread is not the main one

Very similar issue is already discussed here. The problem at hand and what I am trying to achieve is to call a function on a given object in the thread it is created at. Here is the complete case: an instance of class A is created in a given…
Ivan Caravanio
  • 597
  • 1
  • 7
  • 20
1
vote
2 answers

Deadlocks: How do you determine if a call may cause unsafe painting off of the main thread for iOS?

Drawing/painting should always be done on the GUI thread otherwise deadlocks can occur!... How do you determine if a call may cause unsafe painting off of the main thread for iOS? The problem is we get stacks like this which are not on the main…
Cal
  • 1,625
  • 4
  • 20
  • 30
1
vote
1 answer

Load an OpenGl view in the background. iPhone

I have an OpenGL view that renders a 3D model. It is a basic modification on Apples EAGLView. This view is added to a controller's .view and displayed with presentModalViewController: . I would like to do all of the model loading, and OpenGL state…
Joe Cannatti
  • 4,989
  • 5
  • 38
  • 56
1
vote
0 answers

Is it safe to to self destruct an NSThread?

I have a pretty standard setup. I have a UIViewController to handle user interaction and a somewhat long running NSThread that does the actual work when the UI Controller shows up. One issue I've had is when I want to cancel the NSThread. Standard…
EightyEight
  • 3,430
  • 4
  • 36
  • 67
1
vote
1 answer

Stop NSStream runloop in same NSThread

I'm trying to run NSStreams in a thread in my project. I created a thread below: self.thread = [[NSThread alloc] initWithTarget:self selector:@selector(createStreams:) object:handler]; [self.thread start]; And the thread selector implementation is…
Xin
  • 47
  • 7
1
vote
3 answers

Cocoa and getting out of infinite loops

The basic idea I have is to click on one button and enter an infinite loop. I plan to click on another button to stop and get out of this loop. Trouble is once I get into the infinite loop, my second click is never detected so I can't get out. Any…
ZionKing
  • 326
  • 1
  • 4
  • 16
1
vote
3 answers

NSOperationQueue add background threaded operation

I am trying to add a background threaded operation to a NSOperation queue and want to make it execute in a sequence, so I set setMaxConcurrentOperationCount to 1 but not able to achieve synchronous process. I tried with below code, NSOperationQueue…
Anand Suthar
  • 3,678
  • 2
  • 30
  • 52
1
vote
2 answers

NSThread setThreadPriority: is not working

I am using + (BOOL)setThreadPriority:(double)p; to change priority of NSThread but threadPriority is always 0.5. Return value of setThreadPriority: is TURE. _thread = [[NSThread alloc] initWithTarget:self selector:@selector(runThread)…
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
1
vote
2 answers

property declaration for dispatch_queue_t is a 'Semantic Issue"

I am unable to compile dispatch_queue_t as a property using the strong type. When I revert to assign, the thread fails at runtime. I am compiling with OS X 10.10.3 (latest version). @property (nonatomic, strong) dispatch_queue_t…
Antony
  • 187
  • 4
  • 15
1
vote
3 answers

iOS how can i perform multiple NSInputStream

My app uses NSInputStream like below: inputStream.delegate = self; [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [readStream open]; and delegate: - (void)stream:(NSStream *)theStream…
Scinfu
  • 1,081
  • 13
  • 18
1
vote
3 answers

Problem with NSThread

I have a problem with my code I wanna create 2 different instance with NSThread but i think in my problem these doesn't happen. Can you take my a solution for my problem. I post my code, if you can you may show a solution example? Thanks …
zp26
  • 1,507
  • 8
  • 20
  • 38
1
vote
1 answer

Problem with NSThread

I have a question; in my program if i call 2 times [self performSelectorOnMainThread:@selector(callDectectionMove:) withObject:[NSNumber numberWithInt:(int)i] waitUntilDone:false]; I create 2 thread or not? Because in my program i'm not sure to…
zp26
  • 1,507
  • 8
  • 20
  • 38
1
vote
1 answer

Running audio engine in separate thread/process, sending and receiving messages from main thread

I'm writing an iOS application using a separate audio engine which is built in C++. The idea is to have as much of the app as possible written in Swift, running the audio engine as a separate thread or process, and then let the user interface…
Jambaman
  • 741
  • 9
  • 22
1
vote
1 answer

dispatch_async handle event

I know dispatch_async can handle thread. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // handle things that takes a long time dispatch_async(dispatch_get_main_queue(), ^{ // update UI }); …
ronan
  • 1,611
  • 13
  • 20
1
vote
2 answers

I don't know why my view is freezing

I have a big problem since a few days that I can't solve. First I have a login view controller with this code : @implementation MMConnectionViewController @synthesize login, password, activityIndicator, mainVC; -…
Romain Piel
  • 11,017
  • 15
  • 71
  • 106