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

Best multithreading approach in Objective C?

I'm developing an iPad-app and I'm currently struggling with finding the best approach to multithreading. Let me illustrate this with a simplified example: I have a view with 2 subviews, a directory picker and a gallery with thumbnails of all the…
s1m0n
  • 7,825
  • 1
  • 32
  • 45
6
votes
1 answer

How to get a return value from a function which is called through NSthread?

I wrote a function which returns an object. But it is a function which takes data from web.So NSthread is used to call the function. NSThread* pageThread = [[NSThread alloc]initWithTarget:self selector:@selector(threadFunction) object:nil]; How to…
Muhammed Basil
  • 1,834
  • 1
  • 21
  • 39
5
votes
4 answers

How do I create an NSThread that isn't the main thread without performing a selector immediately

I want to create a worker thread that isn't the main thread so I can call ... [self performSelector:@selector(doStuff) OnThread:self.myWorkerThread withObject:nil]; ... in a bunch of locations in my code. How do I create a thread.. any thread and…
Mike S
  • 4,092
  • 5
  • 35
  • 68
5
votes
3 answers

Stopping all animations being performed on different thread

I have a menu with items popping right after each other in intervals of 3 seconds, I'm doing it like so: for(UIButton *menuItem in menuItems){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (0.3 * i) * NSEC_PER_SEC),…
Shai Mishali
  • 9,224
  • 4
  • 56
  • 83
5
votes
4 answers

NSUrlConnection in NSThread - No delegate is executed!

I am using an NSURLConnection in an NSThread but none of the NSURLConnection's delegate methods are executed! I have a main method in my NSTread subclass and a while loop that keeps the thread active. Any help? Sorry for all of this code but I…
Vassilis
  • 2,878
  • 1
  • 28
  • 43
5
votes
2 answers

How a runloop actually works

Earlier this month I asked this question 'What is a runloop?' After reading the answers and did some tries I got it to work, but still I do not understand it completely. If a runloop is just an loop that is associated with an thread and it don't…
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
5
votes
1 answer

Using AsyncSocket with secondary threads on the iPhone

I use AsyncSocket on the iPhone to communicate with a server. AsyncSocket is based on run loops but my app is based on threads. That means, I start a new thread to write data and wait until a response is received on the same thread. But I can't call…
Arthur
  • 151
  • 1
  • 1
  • 6
5
votes
1 answer

Is it sensible to start `CLLocationManager` on a background thread?

According to the documentation of CLLocationManagerDelegate The methods of your delegate object are called from the thread in which you started the corresponding location services. That thread must itself have an active run loop, like the one found…
5
votes
1 answer

Running code from a specific thread in Swift

I have a function like this: func foobar() { let targetThread = Thread.current DispatchQueue.main.async { UIView.animate(withDuration: 0.5, animations: { // Code I need to run on the main thread }, completion: { // Code I…
7ball
  • 2,183
  • 4
  • 26
  • 61
5
votes
1 answer

What does "[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]" do?

I have some problem about NSRunLoop. When run the code as below,the main thread seem to stop and It wouldn't run the code after the while loop. I want to know when [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate…
Slemon
  • 791
  • 7
  • 12
5
votes
2 answers

When to release/retain an object that is passed to a secondary Thread?

I am passing an object to a secondary thread using the following code: (void)login:(id)sender { platformMsgs_LoginRequest *loginRequest = [[[platformMsgs_LoginRequest alloc] init] autorelease]; //more code... [NSThread…
Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
5
votes
1 answer

NSAssert usage in threads

I'm trying to use NSAssert throughout my iPhone app so that if an unexpected condition occurs, the application fails-fast and crashes with a meaningful message in the crash log. This works fine if the failing NSAssert is on the main thread, as it…
Trashpanda
  • 14,758
  • 3
  • 29
  • 18
5
votes
1 answer

meaning of the returned value of [NSThread currentThread]

Could anyone please explain the meaning of the returned value of [NSThread currentThread]? NSLog NSLog(@"%@", [NSThread currentThread]); Result {name = (null), num = 5} What are the following? "NSThread: 0x1e04ed60" name =…
Jerry
  • 1,018
  • 4
  • 13
  • 22
5
votes
3 answers

call a function using thread in xcode

i have created a thread in xcode and i have given the function name to be called from that thread. but my problem is that the function name which is given to call is not being called(came to know when put a breakpoint in that function) code: …
Subrat nayak.
  • 405
  • 1
  • 7
  • 25
4
votes
1 answer

iPhone SDK - Running a repeating process in a background thread

I have an iPhone application which in which I want to perform a method in the background every 1 second. So in my main thread, I have the following code upon my UIViewController viewDidLoad(): [NSTimer timerWithTimeInterval:1.0 target:self…
Brett
  • 11,637
  • 34
  • 127
  • 213