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
3 answers

Why isn't there performSelectorOnMainThread: in NSObject Protocol?

Recently I'm working on app. project for iPhone(iOS). I wonder why there isn't performSelectorOnMainThread: in NSObject Protocol. I need to call to delegate's methods on main thread 'cause they have to handle UI components. Here's sample I…
Henry Kim
  • 21
  • 5
1
vote
1 answer

ObjC threading and non-void functions memory management

Ok, so my question is something I have been looking for for a while. Say the method "first" has been detached as a new thread. -(void)first{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int a; NSMutableArray *array =…
Chance Hudson
  • 2,849
  • 1
  • 19
  • 22
1
vote
1 answer

does the one thread kill the other in a iphone application( both thread are main thread)?

HI guys, ==>in my application i have used three different thread code for one of them is here all thread are of same kind ==>i have defined two thread in appdelegate class ==>one in the root view controller ==>all the thread having different…
NIKHIL
  • 2,719
  • 1
  • 26
  • 50
1
vote
1 answer

How to start a new thread from main thread in an iPhone App

I have an App that is used for mobile shopping. I have a "LocationModel" singleton object that gets a list of addresses from a pList and converts each address into a "Location" object. In the location object I have a "Latitude" and "longitude"…
banditKing
  • 9,405
  • 28
  • 100
  • 157
1
vote
2 answers

Finding out when an NSThread has finished

I have a few functions that I need to call when I press a button. I use [self getamountofdatacenters]; to call these functions. When I press the button, the simulator gets stuck until its done with all the functions, and this takes 5-7 seconds, so…
Emre Akman
  • 1,212
  • 3
  • 19
  • 25
1
vote
1 answer

Running callback on the same thread as the caller in iOS

I call a method on the native iOS side from Kotlin/Native framework. The method does its work asynchronously and responds back with some data in a different thread than it was called with. I want a way to call the response function also in the same…
kerry
  • 2,362
  • 20
  • 33
1
vote
4 answers

Pausing an NSTimer

I have a UIView with a UITableView and a UIImageView in it. The UITableView takes up the top half of the UIView. The UIImageView takes the bottom half of the UIView. I am using an NSTimer to update the image that is being displayed in the…
Chris
  • 5,485
  • 15
  • 68
  • 130
1
vote
1 answer

how many threads is too many in iphone/objective-c dev

I have a complex sync job that does several asyncronous calls for content over HTTP. Each time this content is received, it asks for the next bit and so on. These are all daisey-chained in a big over-all sync job with data on the server. There are…
Mike S
  • 4,092
  • 5
  • 35
  • 68
1
vote
2 answers

Pausing particular thread in iOS?

in my iPhone app, I have used 2 threads. Both functions differently in different class. On particular condition I want to pause particular thread so I have used [NSThread sleepForTimeInterval:] So my question is am I doing right or this sleep causes…
Mahesh
  • 662
  • 2
  • 11
  • 30
1
vote
2 answers

Killing a thread or an alternative

Is there any way I can kill a thread spawn through: [NSThread detachNewThreadSelector:@selector(serverFetchInThread) toTarget:self withObject:nil]; The scenario I am working on is that in my main thread I am letting user enter data in my search bar…
Abhinav
  • 37,684
  • 43
  • 191
  • 309
1
vote
1 answer

Wait for value to change in thread Objective C

I have a thread call in objective C and i want once this thread ends i want to return a value ;the value will be changed inside the thread So the method must not return the value unless the tread ends Here is the code i use: [NSThread…
user1992910
  • 73
  • 3
  • 11
1
vote
1 answer

Objective-C, NSThread detach vs. performSelectorInBackground

What is the differences between these two? [NSThread detachNewThreadSelector:@selector(method) toTarget:self withObject:nil]; [self performSelectorInBackground:@selector(method) withObject:nil]; I normally use the second method to spawn a new…
codereviewanskquestions
  • 13,460
  • 29
  • 98
  • 167
1
vote
3 answers

performSelector NSThread issue

Is it possible to cancel a thread while performSelector waitsUntilDone? See below: I have a while loop with following line: [self performSelector:@selector(getMyRecords:) onThread:myThread withObject:i waitUntilDone:YES] Sometimes, I need to cancel…
random
  • 10,238
  • 8
  • 57
  • 101
1
vote
2 answers

(iphone) which one is more precise timewise: performSelector:afterDelay vs NSTimer

I'm doing animation with performSelector:withObject:afterDelay at 24fps. (reason being, UIImageView doesn't support different interval between images) When I run multiple animations simultaneously, seems like message queued by performselector takes…
eugene
  • 39,839
  • 68
  • 255
  • 489
1
vote
2 answers

Call delegate method from a thread

I've this bit of code: - (IBAction)registerAction:(id)sender { [NSThread detachNewThreadSelector:@selector(registerThread) toTarget:self withObject:nil]; } - (void)registerThread { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; …
patrick
  • 6,533
  • 7
  • 45
  • 66