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
16
votes
4 answers

calling selector with two arguments on NSThread issue

I'd like to make a Thread with multiple arguments. Is it possible? I have the function: -(void) loginWithUser:(NSString *) user password:(NSString *) password { } And I want to call this function as a selector: [NSThread…
okami
  • 2,093
  • 7
  • 28
  • 40
15
votes
7 answers

How to wait for a thread to finish in Objective-C

I'm trying to use a method from a class I downloaded somewhere. The method executes in the background while program execution continues. I do not want to allow program execution to continue until this method finishes. How do I do that?
node ninja
  • 31,796
  • 59
  • 166
  • 254
15
votes
3 answers

NSThread sleepfortimeinterval blocks main thread

I want to simulate a communication with a server. As the remote server will have some delays I want to use a background thread that has on it [NSThread sleepForTimeInterval:timeoutTillAnswer]; The thread is created with NSThread sub…
user1028028
  • 6,323
  • 9
  • 34
  • 59
15
votes
1 answer

How to pause an NSThread until notified?

I have a worker thread that I want to do one bit of its task, then pause & wait for the "ok, continue" command from another thread, then pause & wait, etc. The use case is: the controlling object is a view that I want to display information about…
Olie
  • 24,597
  • 18
  • 99
  • 131
14
votes
1 answer

Perform UI Changes on main thread using dispatch_async or performSelectorOnMainThread?

Possible Duplicate: Grand Central Dispatch (GCD) vs. performSelector - need a better explanation To execute "stuff" on the main thread, should I use dispatch_async or performSelectorOnMainThread? Is there a preferred way, right/or wrong, and/or…
13
votes
2 answers

is it ok to use of a notification to communication back to the main thread of an IOS app? (cf performSelectorOnMainThread)

Is it ok to use of a notification to communication back to the main thread of an IOS app? (cf performSelectorOnMainThread). That is, there are are there any gottcha's for this purpose? Background want to call back to main UI thread from a…
Greg
  • 34,042
  • 79
  • 253
  • 454
13
votes
4 answers

applicationDidEnterBackground and applicationWillEnterForeground method are not called when pressed home button in iOS simulator

I need a long running task to be done in background as well as in foreground. This updates the core data. So to maintain UI responsive I created an another thread where I use different managedObjectContext(MOC). So a timer is set in background as…
aparna
  • 353
  • 2
  • 3
  • 13
11
votes
2 answers

What is meant by CoreData is not thread safe?

In Obj-C, what does it mean in simple terms; "CoreData is not thread safe" OR in general what is "not thread safe" ?
hmthur
  • 2,545
  • 3
  • 20
  • 18
11
votes
2 answers

NSThread number on iOS?

When you print a NSThread's description, you get something like this: {name = (null), num = 1} Is this "num" available somehow? This is for debugging only, so it does not need to clear Apple's approval process.
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
11
votes
4 answers

Can I assign my own "thread names" in Xcode?

Xcode's "thread list" pane shows English-like names for several special threads: com.apple.main-thread, com.apple.libdispatch-manager, com.dispatchfractal.opencl, com.dispatchfractal.opengl, com.apple.root.low-priority,... But for user-created…
Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
10
votes
3 answers

Passing primitives through performSelectorOnMainThread

Ok, so say i have a second thread running, but it wants to manipulate something on the main thread, like a UI item. -(void)backgroundThread { [myButton performSelectorOnMainThread:@selector(setEnabled:) withObject:(BOOL)YES waitUntilDone:YES]; …
Chance Hudson
  • 2,849
  • 1
  • 19
  • 22
10
votes
1 answer

Wait for download task to finish in NSURLSession

My scenario looks like this: I have a class which has a function in it and this function makes a POST request to a server with NSURLSession. In another function which is not in that class I call that function with the task in it, which runs…
ph1psG
  • 568
  • 5
  • 24
10
votes
3 answers

How to wait in NSThread until some event occur in iOS?

How to wait inside the NSThread until some event occur in iOS? eg, We created a NSThread and started a thread loop. Inside the thread loop, there is condition to check whether the message queue has any messages. If there is a message, then it will…
Bharath
  • 198
  • 1
  • 1
  • 9
10
votes
1 answer

AFNetworking - Why does it spawn a network request thread?

I'm trying to understand Operations and Threads better, and looked to AFNetworking's AFURLConnectionOperation subclass for example, real-world, source code. My current understanding is when instances of NSOperation are added to an operation queue,…
edelaney05
  • 6,822
  • 6
  • 41
  • 65
9
votes
2 answers

GCD, NSOperationQueue, or create a thread manually?

When you use threads, do you have any preferences? In general rule, to use any of these techniques : create a new thread manually and use the run loop use NSOperationQueue or use Grand Central Dispatch and the C version with dispatch_queue? Does…
Paul
  • 6,108
  • 14
  • 72
  • 128
1
2
3
48 49