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 run methods in one specific thread (not main thread)

I call a heartBeats method per 10ms in a specific thread(not main thread), how to call another method at any time in this same thread? I subclass NSThread like this @implementation MyThread { NSTimeInterval _lastTimeInterval; } - (void)main { …
Grey
  • 253
  • 4
  • 15
4
votes
1 answer

NSThread with class method?

Is it possible to run a class method (starting with a '+') in a separate thread? Normally I call the method like [myClass myController]; I tried [NSThread detachNewThreadSelector:myController toTarget:myClass withObject:nil]; without success.
4
votes
1 answer

difference between Runloop and thread?

What is run loops actually ? what a difference from thread ? Where we must need to use run loop and where aren't we use ?
virus
  • 1,203
  • 13
  • 21
4
votes
3 answers

Weird behaviour of dispatch_after()

I am writing an application which will do a multiple task simultaneously. One particular task is to do a job once every 200 ms. To achieve this, I am using two methods calling each other. The first method just calls the second and the second method…
4
votes
0 answers

Symbolicate [NSThread callStackSymbols] and [NSThread callStackReturnAddresses]

I would like to symbolicate my [NSThread callStackSymbols] to my method names. My main problem is, that i don't know how to calculate the memory address from the log i got here. 0 MY_APPLICATION 0x000f1ca3 MY_APPLICATION +…
mariusLAN
  • 1,195
  • 1
  • 12
  • 26
4
votes
4 answers

How can I exit [NSRunLoop runUntilDate]?

I am writing an application which has to communicate with a device connected via USB. The app sends and receives data in turns from the device on a fixed timing. All Rx/Tx happens in a separate thread because otherwise the UI would be blocked. The…
insanelygreat
  • 53
  • 1
  • 4
4
votes
3 answers

Thread still running of old view

I have an app where there are five screens. On each screen, in viewDidLoad I am accessing data from server. On each screen I have next button. When I go from screen one to screen five (by clicking Next 4 times), in NSLog, I still see the process…
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
4
votes
2 answers

Pass message between threads in objective c

How I can pass message between 2 threads? For example I have NSThread A and NSThread B and I need to pass message from Thread A to Thread B. How I can check if Thread A is active or completed? and if active then how i can pass message to it. Any…
Kamleshwar
  • 2,967
  • 1
  • 25
  • 27
4
votes
2 answers

Can I stop or cancel loop function when using [NSThread sleepForTimeInterval:2.0]; in IOS

I have a loop function and in it called [NSThread sleepForTimeInterval:2.0];. it mean after 2s, loop function is called. I want when pass new view, this loop function is stop and when back, it is called again. I use this code to call loop…
NGOT
  • 149
  • 5
  • 12
4
votes
1 answer

NSRunLoop returns early, before any FSEvent or timer fires

I'm trying to use a NSRunLoop to watch for FSEvents in an Agent application (that is, without any GUI). I think I understand how a RunLoop works, but I clearly don't, because the behaviour I'm seeing is incomprehensible. What am I missing? (I'm…
Norman Gray
  • 11,978
  • 2
  • 33
  • 56
4
votes
1 answer

Threads that don’t have a runloop

I'm reading Core Animation Programming Guide and in the chapter of "Transactions", I see this Important: When modifying layer properties from threads that don’t have a runloop, you must use explicit transactions. but From Apple's documentation on…
keywind
  • 1,135
  • 14
  • 24
4
votes
3 answers

checking for equality on dispatch_queue_t

How can I check for equality between dispatch_queue_t vars? dispatch_queue_t currentQueue = dispatch_get_current_queue(); dispatch_queue_t mainQueue = dispatch_get_main_queue(); if (currentQueue == mainQueue) { } from the docs: typedef struct…
the Reverend
  • 12,305
  • 10
  • 66
  • 121
4
votes
1 answer

Using +[NSThread sleep:] to resolve a deadlock issue

I just "solved" what appears to be a deadlock or synchronization issue with: [NSThread sleepForTimeInterval:0.1]; in an app that attaches MPMediaItem (music/images) property references from the IPOD library to object instances, and those…
vmanjz
  • 1,156
  • 1
  • 10
  • 23
4
votes
2 answers

Background task doesn't seem to get cancelled/ended

We're currently developing an iOS app that needs to check location in the background. At first, we tried to use significant location changes, but they aren't accurate enough/don't trigger often enough. We considered using region monitoring, but from…
dvyio
  • 339
  • 1
  • 7
  • 20
4
votes
2 answers

RetainCount OK to use in this instance?

RetainCount == BAD retainCount is taboo, unreliable, unpredictable, and in general shouldn't be used. I don't use it anywhere in my code, but I have seen it in one class that I use in an interesting way. I have a class that runs a thread that runs…
Sam
  • 26,946
  • 12
  • 75
  • 101