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
4
votes
1 answer

How to make NSRunLoop work inside a separate thread?

Please look at this code: @interface myObject:NSObject -(void)function:(id)param; @end @implementation myObject -(void)function:(id)param { NSLog(@"BEFORE"); [[NSRunLoop currentRunLoop] runUntilDate:[NSDate…
Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
4
votes
1 answer

Detect when the main thread is locked/busy (IOS)

Is there any way to detect when the main thread is locked/busy (aka will not respond to touch events) ? possible directions check the size of the dispatch_get_main_queue (but i dont know how to manipulate this object to see its size) [[UIApplication…
user353877
  • 1,211
  • 1
  • 15
  • 21
4
votes
2 answers

How to exit NSThread

I am using a thread like this, [NSThread detachNewThreadSelector:@selector(myfunction) toTarget:self withObject the thread is running correctly, I want to quit the thread in the middle,how can I do this.If I use [NSThread exit] the application is…
rajan
4
votes
5 answers

How does multithreading on iPhone OS work? How do I use it?

I am curious about threads on iPhone. Are they easy to establish and to maintain? How does it work on the iPhone? Is it real multithreading?
Thanks
  • 40,109
  • 71
  • 208
  • 322
4
votes
2 answers

Sleep or Pause NSThread

I am creating a new Thread which runs one of my method after every certain period of time. Now what i am doing is as follows: NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(setUpTimerThread) object:nil]; [thread…
Shah
  • 4,990
  • 10
  • 48
  • 70
4
votes
1 answer

Difference between Sleep and NSRunLoop runMode:beforeDate:

I have recently found that when waiting for my NSURLConnections to come through it works much better if I tell the waiting thread to do: [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; instead of…
TurqMage
  • 3,321
  • 2
  • 31
  • 52
4
votes
3 answers

Background thread NSRunloop run does not exit after NSTimer is invalidated! Why?

I'm creating an NSTimer and adding it to the runloop of a background thread. My code is like the background thread example for this answer: iPhone-SDK:Call a function in the background? After creating the timer and attching it to the runloop from…
Cal
  • 1,625
  • 4
  • 20
  • 30
4
votes
2 answers

iOS Threads Wait for Action

I have a processing thread that I use to fill a data buffer. Elsewhere a piece of hardware triggers a callback which reads from this data buffer. The processing thread then kicks in and refills the buffer. When the buffer fills up I am currently…
TurqMage
  • 3,321
  • 2
  • 31
  • 52
4
votes
4 answers

Detect end of performSelectorInBackground:withObject:

I have an asynchronous server request in my iOS app: [self performSelectorInBackground:@selector(doSomething) withObject:nil]; How can I detect the end of this operation?
cuSoon
  • 81
  • 1
  • 3
4
votes
0 answers

Put run-loop-based NSThread to sleep for an indeterminate amount of time

I have a dedicated networking thread in my iOS app. The thread's -main method looks like this: - (void)main { @try { while (!self.isCancelled) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]…
LinenIsGreat
  • 594
  • 4
  • 13
4
votes
3 answers

Does every thread need its own autorelease pool?

Does every thread have to have its own pool? I am writing an iPhone app which uses threads. If I do not put a pool on a thread it complains abut leaking. What I wanted to do was to store some object which outlives the thread. How can I do it?
John Smith
  • 12,491
  • 18
  • 65
  • 111
4
votes
2 answers

Setting Local Notifications on a new thread?

I need to know if it is possible to create a new thread to handle setting local notifications. My app depends heavily on these notifications, so I want to make the app work while the phone sets the notifications. Example: (now) you launch the app,…
Mazyod
  • 22,319
  • 10
  • 92
  • 157
4
votes
1 answer

Convert pthread_t to NSThread

I need check whether pthread_t is main thread. I want do it from current thread (not from pthread_t which I need check and not from main thread). My code (pt is pthread_t) NSThread *thread = CFBridgingRelease(pt); // it works wrong bool isMain =…
Katya
  • 300
  • 3
  • 14
4
votes
2 answers

Schedule NSStreams on secondary thread

In an iPad app I'm developing, I need to put the network handling on a separate thread since it occasionally blocks the UI of the app. At the moment, I have created a Connection object in which all the networking logic goes (NSStreams and its…
Bart Jacobs
  • 9,022
  • 7
  • 47
  • 88
4
votes
2 answers

Finding all active threads

I need to find a way to enumerate all my iPhone application's active threads. This is strictly for debug purposes. Private APIs, if any, are welcome as well. I know I can see all the current threads in the debugger window, but I would like to have…
Mihai Damian
  • 11,193
  • 11
  • 59
  • 81