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

Realtime audio thread issues (iOS)

I have the following setup: Core Audio Callback -> Circular Buffer -> libLAME -> Circular Buffer -> libShout This all works fine until I start doing any intensive work at which point the thread doing the encoding (libLAME) and the thread doing the…
3
votes
3 answers

The best way to pause execution of WHILE loop in Objective-C

while(...condition...) { //do something NSDate *date = [NSDate date]; NSTimeInterval milliseconds = [date timeIntervalSince1970]; [NSThread sleepForTimeInterval:0.2]; date = [NSDate date]; NSTimeInterval milliseconds1 = [date…
boopathy
  • 427
  • 2
  • 9
  • 20
3
votes
1 answer

iPhone app freezes when parsing XML

My app freezes whenever I parse an XML feed. I have tried calling this instead: [NSThread detachNewThreadSelector:@selector(parseXML) toTarget:self withObject:nil]; which calls: -(void) parseXML { NSAutoreleasePool *pool = [[NSAutoreleasePool…
Zac Altman
  • 1,215
  • 4
  • 25
  • 37
3
votes
2 answers

MKAnnotation don't appear in map using NSThread

I have a method that inserts annotations in the map. This method is called by a delegate method of map. The problem is that the annotations don't appear in map. I have to touch the map one more time to show the annotations. After inserting the…
Alessandro Garcez
  • 728
  • 2
  • 6
  • 25
3
votes
2 answers

OS X Cocoa timer not fired when application on background

A third-party library provides a function I need to call every 100ms. Setting up a timer to do that works very well as long as my app is on foreground. When my app is on background timer works for a while but after a about a minute timer is called…
superg
  • 379
  • 1
  • 6
  • 19
3
votes
4 answers

How to force screen update for UIScrollView from non-UI thread/function (iPhone)

I am drawing a set of images on the uiscrollview from a non-ui thread/function. But its only displayed after all the images are done drawing. For drawing all the images, I have written a function and that is what is being called as the non-ui…
wolverine
  • 2,967
  • 5
  • 31
  • 35
3
votes
2 answers

Objective-C NSThread ref counting convention (retain vs autorelease)

My main program spawns a thread, which executes the following: // alloc autorelease pool somewhere before NSArray *blah = [NSArray arrayWithObject: @"moo"]; [self performSelectorOnMainThread: @selector(boonk:) withObject: blah waitUntilDone:…
MarcWan
  • 2,943
  • 3
  • 28
  • 41
3
votes
1 answer

Proximity sensor affects thread that plays audio

An iPhone app starts a thread using NSThread that plays short audio tick on regular intervals to give pace. Code that starts and plays sound: tickingThread = [[NSThread alloc] initWithTarget:self …
matejk
  • 798
  • 1
  • 14
  • 27
3
votes
3 answers

perform background task on different thread in iOS

How to preform certain operation in background on different thread, if it is executed on main thread it is blocking the UI of my app. any one have any idea how to do it? even if it prints NSLog in background it will be fine. i want to run following…
Ravi_Parmar
  • 12,319
  • 3
  • 25
  • 36
3
votes
2 answers

Why is tableView:cellForRowAtIndexPath: being called on a background thread?

In my iPhone app, I am occasionally seeing a crash caused by tableView:cellForRowAtIndexPath: being called on a background thread. Obviously, this should not be happening. I'm not calling it, my object is a delegate to a UITableView and the…
Jordan
  • 117
  • 1
  • 12
3
votes
1 answer

Crashes in __CFTSDFinalize

we have a serious crashing bug we can absolutely not get a hold of. The problem is that it happens to happen asynchronously in the background, obviously when the dispatch system cleans up a worker thread. Here are two example stack traces: Thread 7…
Max Seelemann
  • 9,344
  • 4
  • 34
  • 40
3
votes
0 answers

Running two NSStreams in two different threads

My app runs a network task in a separate thread - it gets data from my server, processes it and displays the results on an ongoing basis. This works fine when I have only one such network connection in one thread. However, if I run a second thread…
R.S
  • 321
  • 3
  • 15
3
votes
2 answers

What's wrong with this dealloc in ARC?

I am working on an app that does image processing and displays the resulting image. Im using UIScrollView to let user scroll all images, because the image is not a standard jpg or png, it takes time to load. I use GCD to load asynchronously, when…
chancyWu
  • 14,073
  • 11
  • 62
  • 81
3
votes
1 answer

NSThread callStackSymbols from another thread?

I have a background thread that polls UI thread every 200ms. If there is a hang for 2 seconds, I would like to get the call stack from UI thread at that point. When I call [NSThread callStackSymbols], it is executed on background thread since I…
ilker Acar
  • 401
  • 1
  • 5
  • 11
3
votes
1 answer

Asynchronous texture loading iPhone OpenGL ES 2

I'm creating and loading a lot of textures (made of strings). To keep the animation running smoothly, I offload the work to a separate worker thread. It seems to work more or less exactly the way I want, but on older devices (iPhone 3GS) I sometimes…
hanno
  • 6,401
  • 8
  • 48
  • 80