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
1
vote
1 answer

How to Stop a currently executing thread

Scenario is like this-- In my app there is an Scroll View with many instances of MyCustomImageDownloaderController(containing imageViews where images are to be assigned after downloading) . As per our requirement, an image has to be downloaded as…
Rohit Singhal
  • 381
  • 1
  • 4
  • 22
1
vote
2 answers

NSThread is blocking my GUI

I use a NSThread in order to download videos and images from a server side.It work looks and works great except the fact that when the downloading is done my GUI gets blocked until the download is complete.When the download is finished it takes a…
adrian
  • 4,574
  • 17
  • 68
  • 119
1
vote
2 answers

How to stop the execution of a thread in iphone

I want to stop the execution of the thread.I used "iscancelled" but there is something going wrong..After cancelling the thread it's execution does not stop. NSLog(@"YES-------%d,%d", [myThread isExecuting], [myThread…
Rohit Singhal
  • 381
  • 1
  • 4
  • 22
1
vote
3 answers

NSThread reading parent's ivars?

I detach a new NSThread withObject:self so that the thread can callback the main thread as a delegate. However, I also need the new thread to be able to read some values in the parent. With NSThread, I can only pass one object withObject, and I'm…
Adam
  • 913
  • 1
  • 9
  • 26
1
vote
2 answers

iOS: EXC_BAD_ACCESS caused by running timer in NSThread?

I have been having some crashes in my app. When checking the logs and using atos, it is telling me exactly where I get the crash, which is where I tell my NSRunLoop to run: /** * Create a new thread for the timer * * @version $Revision: 0.1 …
Nic Hubbard
  • 41,587
  • 63
  • 251
  • 412
1
vote
5 answers

how to buffer incoming events/notifications your iPhone app is observing so as not to trigger event code for each event?

What is the best way to buffer incoming events/notifications your iPhone app is observing so as not to trigger event code for each event? A code sample would be great... e.g. would it be to create an NSMutableArray in the controller to add each…
Greg
  • 34,042
  • 79
  • 253
  • 454
1
vote
1 answer

Establish relationship between managed objects in two different contexts

I am parsing JSON string to create new managed objects in a separate thread and in a separate managed object context. Later I want to merge the changes in the main thread by listening to NSManagedObjectContextObjectsDidChangeNotification. The…
1
vote
3 answers

Memory management with NSThread

I have an app that needs to signal continuously a word in morse code. I did this by creating an NSThread and running some code inside the selector with a "while loop". Here is the code: @implementation…
Alex Albu
  • 693
  • 1
  • 12
  • 20
1
vote
1 answer

Threads and autoreleasepool questions

As I understand there are several ways to send tasks to be performed in threads. The most common ones that I use are: 1) performSelector:withObject:afterDelay: 2) performSelectorOnMainThread:withObject:waitUntilDone: 3) …
1
vote
3 answers

Accurate repeating iPhone sounds

I am working with an app that needs to play a sound "tap" at 60 ms intervals (making for 1000 taps per minute). When I get past about 120 ms intervals (500 taps per minute), the sounds become very erratic and seem to be piling up on one another. The…
TheTwoNotes
  • 453
  • 3
  • 15
1
vote
1 answer

iOS - how to be notified when a thread (using GCD) ends it's job

I'm start to use GCD, and I need to know when a certain thread has ended it's job. My code: dispatch_queue_t registerDeviceQueue = dispatch_queue_create("RegisterDevice", NULL); dispatch_async(registerDeviceQueue, ^{ [self registerDevice]; …
Rui Lopes
  • 2,562
  • 6
  • 34
  • 49
1
vote
2 answers

NSURLConnection and NSTIMER issue

I am currently trying to have a time out of 20 second when making an async request. The issue am having is that the NSURLconnection runs on the main thread and therefore, if I run an NSTIMER to count the number of seconds that has passed, it never…
user281300
  • 1,427
  • 2
  • 19
  • 31
1
vote
1 answer

Runloop not getting fired when scheduled with streams

I'm currently doing a FTP client for my project. I've scheduled the readstream/writeStream with the runloop to read the file from the harddisk/write the file to the harddisk and send it to the server. After uploading and downloading the file I…
sivakumar
  • 21
  • 4
1
vote
2 answers

Alternate to sleeping NSThread for pause

Right now I'm sleeping my main thread in order to have my application pause before running an action. [NSThread sleepForTimeInterval:0.75];. I know that that is less than ideal from a programming perspective, what other options do I have?
Peter Kazazes
  • 3,600
  • 7
  • 31
  • 60
1
vote
1 answer

objective c Thread in Thread variables life time

I have an NSOperation where inside its -main method I use [NSThread detachNewThreadSelector:@selector(aMethod:) toTarget:self withObject:anArgument]; aObject (instance variable of my NSOperation subclass) is a weak reference to an object of an…
Vassilis
  • 2,878
  • 1
  • 28
  • 43