nsthread

GCD, NSOperationQueue, or create a thread manually?

天涯浪子 提交于 2019-12-03 03:45:16
When you use threads, do you have any preferences? In general rule, to use any of these techniques : create a new thread manually and use the run loop use NSOperationQueue or use Grand Central Dispatch and the C version with dispatch_queue? Does NSOperationQueue simplify everything, and thus is better to be used when we need to create an asynchronous function? I'm lazy, so my philosophy is to pick the simplest solution that does everything I need it to. (I like to think this is the "lazy" espoused by Larry Wall but sometimes I wonder.) So my order of preference would be: Asynchronous method

need some clarifications about dispatch queue, thread and NSRunLoop

此生再无相见时 提交于 2019-12-03 02:22:34
问题 The following things are what I know & understand: Global queue is a concurrent queue which can dispatch tasks to multiple threads. The order of executing task is not guaranteed. e.g.: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), { for (int i; i<10; i++) { doTask() } }) If I want to dispatch to serial queue, I can use dispatch_async(dispatch_queue_create("my.serial.queue", nil) { ... } each time only one task is dispatched to a thread & get executed. The order

Creating threads in swift?

孤街浪徒 提交于 2019-12-03 00:21:30
I am trying to spawn a thread in swift. So I have this line: . . . let thread = NSThread(target: self, selector: doSomething(), object: nil) . . . doSomething is a function within the scope of the class. That line gives this error: "could not find an overload for init() that accepts the supplied arguments" What am I missing here? Ho can I create a new thread in swift? As of Xcode 7.3 and Swift 2.2, you can use the special form #selector(...) where Objective-C would use @selector(...) : let thread = NSThread(target:self, selector:#selector(doSomething), object:nil) NSThread takes a selector as

Potential reference count issues unless grabbing fresh reference in background thread

元气小坏坏 提交于 2019-12-02 18:35:57
问题 I have a second question after reading Marcus S. Zarra's (excellent) Core Data: Data Storage and Management for iOS, OS X, and iCloud (2nd edition) if I may. The book's section Asynchronously Adding the NSPersistentStore contains this piece of code (excerpt): dispatch_queue_t queue; queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ // ... NSPersistentStoreCoordinator *coordinator = nil; coordinator = [[self managedObjectContext]

Which is the best of GCD, NSThread or NSOperationQueue? [closed]

纵饮孤独 提交于 2019-12-02 16:19:46
What's the best way of multithreading in iOS as we have three options GCD, NSThread , and NSOperationQueue ? I am confused in which one is the best? If none, then which should be used in what scenario and how they differ and also, if someone has some good example of using NSOperationQueue , please share so that I can learn. Simple answer: Use NSThread (or even the pthreads API) when you want or need to have direct control over the threads you create, e.g. you need fine-grained control over thread priorities or are interfacing with some other subsystem that vends/consumes thread objects

need some clarifications about dispatch queue, thread and NSRunLoop

天大地大妈咪最大 提交于 2019-12-02 15:54:53
The following things are what I know & understand: Global queue is a concurrent queue which can dispatch tasks to multiple threads. The order of executing task is not guaranteed. e.g.: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), { for (int i; i<10; i++) { doTask() } }) If I want to dispatch to serial queue, I can use dispatch_async(dispatch_queue_create("my.serial.queue", nil) { ... } each time only one task is dispatched to a thread & get executed. The order is FIFO. ===== What I am confused & not fully understand ======= The main thread has a NSRunLoop,

Running NSTimer Within an NSThread?

妖精的绣舞 提交于 2019-12-02 13:05:58
问题 I am trying to run a timer in the background of my application, i am using the timer heavily in my application and i'd rather running it in the background, However i am getting memory leaks when trying to release the NSAoutreleasePool. My Timer class is singleton, so if i start new timer the old timer get dealloc it . + (void)timerThread{ timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread) object:nil]; //Create a new thread [timerThread start]; //start the

iPhone: unrecognized selector error

人盡茶涼 提交于 2019-12-02 10:04:40
I'm threeaing some tasks like this : RootViewController - (void)viewDidLoad { [NSThread detachNewThreadSelector:@selector(findSomething) toTarget:self withObject:nil]; } - (void) findSomething { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; doMoreThings [pool release]; } - (void) doMoreThings { doMoreMoreMoreThings on different objects } - (void) foundSomething:(NSFoundThing*)foundObj { do your stuff } oneObject - (void) doMoreMoreMoreThings { do things [self performSelectorOnMainThread:@selector(foundSomething:) withObject:thingFound waitUntilDone:NO]; } gives -[KMLParser

Potential reference count issues unless grabbing fresh reference in background thread

爱⌒轻易说出口 提交于 2019-12-02 07:36:55
I have a second question after reading Marcus S. Zarra's (excellent) Core Data: Data Storage and Management for iOS, OS X, and iCloud (2nd edition) if I may. The book's section Asynchronously Adding the NSPersistentStore contains this piece of code (excerpt): dispatch_queue_t queue; queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ // ... NSPersistentStoreCoordinator *coordinator = nil; coordinator = [[self managedObjectContext] persistentStoreCoordinator]; // ... }); It also contains this explanation: The reason we grab a fresh reference to the

Running NSTimer Within an NSThread?

≡放荡痞女 提交于 2019-12-02 05:05:50
I am trying to run a timer in the background of my application, i am using the timer heavily in my application and i'd rather running it in the background, However i am getting memory leaks when trying to release the NSAoutreleasePool. My Timer class is singleton, so if i start new timer the old timer get dealloc it . + (void)timerThread{ timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(startTimerThread) object:nil]; //Create a new thread [timerThread start]; //start the thread } //the thread starts by sending this message + (void) startTimerThread { timerNSPool = [