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
9
votes
2 answers

What is the difference between +[NSThread detachNewThreadSelector:toTarget:withObject:] and -[NSObject performSelectorInBackground:withObject:]?

They seem to perform a reasonably similar task: launching a new thread that performs that selector quickly and easily. But are there any differences? Maybe with regards to memory management?
Grant Paul
  • 5,852
  • 2
  • 33
  • 36
9
votes
1 answer

NSTimer never starts

I'm just trying to close an NSPanel after a couple second delay, but I can't get my NSTimer to start. It will fire if I explicitly call the fire method on it, but it will never go by itself. Here's my code: -…
strange quark
  • 5,205
  • 7
  • 41
  • 53
9
votes
2 answers

Swift 2 - iOS - Dispatch back to originating thread

So I have an application that fires a series of asynchronous events and then writes the results to a buffer. The problem is that I want the buffer to be written to synchronously (in the thread that spawned the asynchronous process) skeleton code is…
Ajwhiteway
  • 986
  • 1
  • 9
  • 23
9
votes
2 answers

How to stop a NSThread sub-thread in iphone

I created a sub-thread using NSThread in main thread NSThread *newThread = [[NSThread alloc] initWithTarget:self selector:@selector(MyThread:) object:timer]; 5 sec later,i used [newThread cancel] in main thread to stop the sub-thread,but it didnt…
None
  • 273
  • 1
  • 3
  • 11
9
votes
2 answers

does NSThread create autoreleasepool automatically now?

I have test code like this - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil]; [thread start]; } -(void)test { MyClass *my = [[[MyClass alloc]…
eliudnis
  • 239
  • 3
  • 6
9
votes
3 answers

Creating threads in swift?

I am trying to spawn a thread in swift. So I have this line: . . . let thread = NSThread(target: self, selector: doSomething(), object: nil) . . . doSomething is a function within the scope of the class. That line gives this error: "could not find…
zumzum
  • 17,984
  • 26
  • 111
  • 172
9
votes
1 answer

Is it possible to determine the NSRunLoop/NSThread that is associated with an open NSStream?

I am using (and am required to use) a third-party framework to which I do not have source. The third-party framework handles creating an authenticated client/server connection and hands back a pair of open NSStreams. The stream creation process, per…
xyzzycoder
  • 1,831
  • 13
  • 19
8
votes
1 answer

Run method on main thread from another thread

My model class has to get some data from the internet. So I decided to run it on another thread so the ui doesn't freeze. So when an object wants some data it first asks the model using a method of this type: - (void)giveMeSomeData:(id)object…
user531461
8
votes
4 answers

setKeepAliveTimeout and BackgroundTasks

I've a big headache with the topic. I'm working on an application that needs to poll a webserver regularly, in order to check for new data. Based on the returned information, I wish to push a local notification to the user. I know that this approach…
valvoline
  • 7,737
  • 3
  • 47
  • 52
8
votes
1 answer

Subview in Main View crash When assigning Image from AVFoundation to UIImageView

I have created a custom AVFoundation camera and loaded into another view as subview with @IBDesignable, after the image is taken I would like to assign it to UIImageView, But when the button is pressed, the custom camera view (UIView) crash and move…
Brian Nezhad
  • 6,148
  • 9
  • 44
  • 69
8
votes
3 answers

dispatch_semaphore_t reuse - What am I missing here?

I have some code where I am using dispatch_semaphore_t to signal operation completion. When the semaphore is a member variable, it does not seem to behave correctly. I will show example code that works and an example that does not seem to…
GTAE86
  • 1,780
  • 3
  • 29
  • 39
8
votes
4 answers

Naming Threads in an NSOperationQueue

NSOperationQueue creates many threads, as you'd expect, and desire. But when you pause the app and debug it in Xcode, it's unclear which threads belong to one operation queue and which belong to another. I've tried: [NSThread currentThread] setName:…
Nick Locking
  • 2,147
  • 2
  • 26
  • 42
8
votes
1 answer

NSMenu animations block main thread

I have: NSStatusItem with a custom view (scrolling text in a secondary thread), with the secondary thread updating the internal state and notifying the main thread with setNeedsDisplay. On mouseDown, an NSMenu pops up. However, if any NSMenuItem in…
tentonwire
  • 81
  • 1
7
votes
1 answer

NSThreads in Automatic Reference Counting(ARC)

i am trying to use NSThreads with ARC in 4.3.5. With iOS 5 everything works perfect, but if i try it on a older iOS like 4.3 its leaking. Normally i would use a Autoreleasepool for NSThreads but since there is no manual Autoreleasepool in ARC i…
7
votes
1 answer

Crash - "Collection was mutated while being enumerated."

Goal is to "launch a spinner graphic at start of viewWillAppear that loads data before showing the tableview" so the user doesn't wonder why there's a delay before seeing the table. I.e. a UIActivityIndicatorView has been added to the window, and I…
Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
1 2
3
48 49