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

Why isn't my use of NSLock working?

I am writing code to render and rotate a picture whose details are being simultaneously calculated and updated. It works error-free on a single thread (with a display link), but looks clunky, and I don't want the calculations to be triggered by the…
Racing Tadpole
  • 4,270
  • 6
  • 37
  • 56
3
votes
2 answers

NSTask blocks main thread

From my main thread I call a selector using [self performSelectorInBackground:@selector(startTask) withObject:nil]; This is the method startTask: -(void)startTask{ NSTask *task = [[NSTask alloc] init]; NSPipe *pipe = [[NSPipe alloc]…
Daniel
  • 1,473
  • 3
  • 33
  • 63
3
votes
3 answers

po [NSThread currentThread]

When I do po [NSThread currentThread], I got {name = (null), num = 4} When I look to the left I see: Looks like it's Thread number 6, not 4. Also what properties do we need to call to get that thread numbers anyway? [NSThread…
user4951
  • 32,206
  • 53
  • 172
  • 282
3
votes
1 answer

iOS - Background processes and UI update

the question is simple : my app control if there is an update every time it starts. If there is an update a popup will be shown with a Yes or No choose. When user tap Yes 4 methods start. These methods download xml file and upload CoreData. This is…
Andrea Mario Lufino
  • 7,921
  • 12
  • 47
  • 78
3
votes
0 answers

iOS Background task (NSThread) dies

Some days ago I posted a question about NSThread. Finally I managed to make it run in background every minute. The aim of the app is to get the location and then call to a webservice to update it on a server with ASIHTTPRequest every X minutes. The…
Ibaivi
  • 51
  • 4
3
votes
1 answer

How to run an asynch process in an NSOperation

I have a need to update some data from a webservice via a background thread in an app I'm working on. Normally I'd just do this via an NSOperationQueue and a synchronous web request in the main() function of the NSOperation. However, for this…
cpjolicoeur
  • 12,766
  • 7
  • 48
  • 59
3
votes
1 answer

Call one method with more than one parameter from a NSThread

How can i call one method from a NSThread? i can call one method like below: [regionsMapView addAnnotation:addAnnotation]; How can i call that in a NSThread? I have used like below: [NSThread detachNewThreadSelector:@selector(addAnnotation) …
itsazzad
  • 6,868
  • 7
  • 69
  • 89
3
votes
0 answers

What exactly is GCD overcommit and is it dangerous

I've been working on some code recently where I want to ensure that certain tasks run sequentially always execute on the same thread. As an experiment to get a feel for how this would work I created my own thread using this example Thread Example My…
dubbeat
  • 7,706
  • 18
  • 70
  • 122
3
votes
4 answers

how to stop nsthread

I am using a thread to update messages in background in my application. The thread is started in my messages class. Messages.m timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread:) object:nil];…
sujith1406
  • 2,822
  • 6
  • 40
  • 60
3
votes
1 answer

Loading screens in games (ensuring animations don't stutter during the transition)

I have a cocos2d game, it performs at between 55 and 60fps once the game is loaded and running. However, due to using sprite sheets for both my menu's and game (one for each), there was a point of crossover when loading the game which would cause…
Bongeh
  • 2,300
  • 2
  • 18
  • 30
3
votes
3 answers

iPhone - Help with MBProgressHUD, Sudzc, Web Services and NSThread

I have the following code, which connects to a web service and returns an array of Categories. I am using the following wrapper for SOAP web services: http://www.sudzc.com/ ..and the following MBProgressHUD for the activity…
gotnull
  • 26,454
  • 22
  • 137
  • 203
3
votes
1 answer

NSTimer memory manage question

By default an object returnd by method alloc or copy has retain count equals to 1, so you have to release it by yourself. But through NSTimer sample codes // in one method start the timer (which myTimer is an Class Instance) myTimer = [NSTimer…
xhan
  • 6,057
  • 4
  • 33
  • 47
3
votes
4 answers

iPhone: starting an NSThread from a C++ object

I'm writing a game for the iPhone. Almost all the code is written in C++. Now I'd like to create a new thread using NSThread (I want to use the runLoop). It's possible to mix objective-C and C++ if the code is written in a .mm file, which I did. The…
Mat
  • 111
  • 1
  • 5
3
votes
1 answer

Objective-C: Execute block or function in specific NSThread

NSObject has a method -performSelector:onThread:withObject:waitUntilDone: that allows executing any method on the calling object in a specific NSThread. Is there a similar and convenient way to execute a C-style function or block in a specific…
Bri Bri
  • 2,169
  • 3
  • 19
  • 44