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

NSTask or NSThread?

I have some code that is attached to an NSTimer. Around 5 times every second, it interacts with another application (by emulating keystrokes) and when appropriate spits out an NSNotification, that is handled by another piece of code. While the…
Ben Packard
  • 26,102
  • 25
  • 102
  • 183
2
votes
0 answers

No visible @interface for 'NSThread' declares the selector 'start'

Ok, so I have been at this for about 2 hours now. I can get the following lines of code to run in the simulator, but I cannot get it to compile on the device and I dont know why. I keep getting the compile error 'No visible @interface for 'NSThread'…
DrRocker
  • 655
  • 1
  • 7
  • 14
2
votes
1 answer

How do i schedule something in the runloop of another thread?

I am writing an application that is going to send/receive data over tcp connections and I wanted to schedule the read/write to happen in the run loop of a different thread. Meaning Thread 1 is creating the connection and scheduling it on the run…
Shehzan
  • 287
  • 4
  • 12
2
votes
1 answer

iOS, how to restart NSThread?

To restart the NSSthread, I'm using the code below: - (IBAction)listen:(id)sender { thread = [[NSThread alloc] initWithTarget:self selector:@selector(listen1) object:nil]; [thread start]; [thread cancel]; [thread start]; } But when I built and…
Matsu
  • 55
  • 5
2
votes
1 answer

iOS App freezing with NSConditionLock

I'm having this wierd problem with the app freezing at a certain point. I'm guessing its got to do with how I'm using NSConditionLock. Theres a library I have been given to use, which consists of a series of survey questions, but it works in such a…
Akash Malhotra
  • 1,106
  • 1
  • 17
  • 30
2
votes
2 answers

How to pause the execution of While loop in Objective c?

I want to pause the execution of while loop for 200 milliseconds.I have used [NSThread sleepForTimeInterval:0.2] ,It's working fine for me but, I want to know what are the alternative ways to pause execution of while loop?
boopathy
  • 427
  • 2
  • 9
  • 20
2
votes
4 answers

pthread vs NSThread: which is faster

In Cocoa, is NSThread faster than pthread? is are any performance gain? is it negligible to ignore?
ReachConnection
  • 1,831
  • 6
  • 22
  • 32
2
votes
2 answers

Sprite animation not working in NSThread method in Cocos2d

I created a Thread like the below one: [NSThread detachNewThreadSelector:@selector(connectionFinishedThread) toTarget:self withObject:nil]; inside this method, i created one sprite and given animation for this sprite. Animation not visible. My code…
Hari Babu
  • 891
  • 1
  • 9
  • 22
2
votes
1 answer

autorefreshing uiviewcontroller in ios 5.1

I am having a UIViewController that shows progress status of an calculations that are done on my Iphone app, to see the percent of the progress I need to push button called refresh on the same UIViewController, how can I make that automatically done…
user2960510
  • 1,123
  • 2
  • 8
  • 9
2
votes
3 answers

How to get a "parent" thread for NSThread in iOS?

Assuming the "parent" thread is not the main thread. How can I know from the thread what thread has triggered its creation? Example: Main thread triggers creation of ThreadA ThreadA triggers creation of ThreadB In ThreadB I want to know that…
mafonya
  • 2,152
  • 22
  • 21
2
votes
1 answer

Multiple NSThreads synchronization

I want to achieve the following task using NSThread I've a main thread and three (3) workerThread T1, T2, T3. All these started at the same time from main thread, Main thread has an int size variable. Now I want to synchronize all three threads in a…
Marvi
  • 23
  • 3
2
votes
2 answers

Crash on NSOperation deallocation in NSManagedObjectContext

I am experiencing a problem with CoreData when an NSOperation that download stuff in the background is beeing deallocated. I am using the nested managed object contexts and the context the operation uses has everything guarded in…
Michael Ochs
  • 2,846
  • 3
  • 27
  • 33
2
votes
3 answers

Thread extracting substring from NSString

I'm doing some work using the RedPark Serial Cable for iOS. This is a cable that allows serial communication between an iOS device and another device like a microcontroller. There is a method that comes with the RedPark SDK that reads the bytes…
David Evans
  • 213
  • 1
  • 2
  • 12
2
votes
2 answers

UITabBar appearance problem + NSThreads

I'm having a problem when trying to add a UITabBar as a subview of my AppDelegate's window. The link above shows a screenshot of the messy state of the screen. TabBarInAMessyState.png The results are unpredictable. In this picture only the…
Eduardo Coelho
  • 1,953
  • 8
  • 34
  • 60
2
votes
2 answers

How to run another thread and using that thread run timer to repeat process?

Hi i want to start a timer with another thread and want to repeat process in that thread. i had tried but it doesn't work. my code snippet is given below [NSThread detachNewThreadSelector:@selector(setupTimerThread) toTarget:self …
jpd
  • 381
  • 1
  • 2
  • 13