grand-central-dispatch

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

。_饼干妹妹 提交于 2019-12-03 03:59:05
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . What's the best way of multithreading in iOS as we have three options GCD, NSThread , and NSOperationQueue ? I am confused in which

Core Data saving objects in background issue

江枫思渺然 提交于 2019-12-03 03:58:55
问题 What I'm trying todo in a nutshell is I am using a background queue to save JSON objects pulled from a web service to the Core Data Sqlite3 database. The saving takes place on a serialized background queue I've created via GCD, and saved to a secondary instance of NSManagedObjectContext that is created for that background queue. Once the save is complete I need to update the instance of NSManagedObjectContext that is on the main thread with the newly created/updated objects. The problem I am

Core Data & GCD: Passing the correct managed object context to custom NSManagedObjects

只谈情不闲聊 提交于 2019-12-03 03:58:31
I get runtime errors which seem to result from my incorrect implementation of GCD in combination with my custom NSManagedObjects. Nested in a GCD call, I am using custom NSManagedObjects which (seem to) have their own managed object contexts (= self.managedObjectContext ). I am creating the managed object context in the app delegate by using the managed object context provided by UIManagedDocument : self.managedDocument.managedObjectContext . I don't understand how to pass the correct managed object context down to my custom NSManagedObjects. How would I need to change my code to use the

What will happen if I have nested dispatch_async calls?

一笑奈何 提交于 2019-12-03 03:47:10
问题 It may be a dumb question but I need to ask and clear this up for myself. To submit a block onto a queue for execution, use the functions dispatch_sync and dispatch_async . They both take a queue and a block as parameters. dispatch_async returns immediately, running the block asynchronously, while dispatch_sync blocks execution until the provided block returns. Here are some situations: Situation 1 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);

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

Why is dispatch_sync on custom concurrent queue deadlocking

a 夏天 提交于 2019-12-03 03:17:44
I'm seeing an intermittent deadlock in my app when using dispatch_sync on a custom concurrent dispatch_queue. I'm using something similar to the method described in Mike Ash's blog to support concurrent read access but threadsafe mutations on an NSMutableDictionary that acts as a cache of currently active network RPC requests. My project uses ARC. I create the queue with: dispatch_queue_t activeRequestsQueue = dispatch_queue_create("my.queue.name", DISPATCH_QUEUE_CONCURRENT); and the mutable dictionary with NSMutableDictionary *activeRequests = [[NSMutable dictionary alloc] init]; I read

When to use Semaphore instead of Dispatch Group?

此生再无相见时 提交于 2019-12-03 03:16:04
问题 I would assume that I am aware of how to work with DispatchGroup, for understanding the issue, I've tried: class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() performUsingGroup() } func performUsingGroup() { let dq1 = DispatchQueue.global(qos: .userInitiated) let dq2 = DispatchQueue.global(qos: .userInitiated) let group = DispatchGroup() group.enter() dq1.async { for i in 1...3 { print("\(#function) DispatchQueue 1: \(i)") } group.leave() } group.wait()

What is the proper method/accepted standard for loading data asynchronously into table view cells?

三世轮回 提交于 2019-12-03 02:59:57
Many apps such as Tweetbot , Twitterrific , Alien Blue , etc. that display images from an API seem to load them in an asynchronous manner. It seems the initial viewable images are loaded synchronously – that is the initial viewable cells aren't displayed until their images are ready – but when scrolling further down past the initial viewable cells, it seems the images for those new cells are loaded independently of the initial synchronous load. For example, when the user loads tweets in a Twitter app, the initial six or seven tweets that will be visible aren't shown until the images for the

Grand Central Dispatch (GCD) dispatch source flags

北城余情 提交于 2019-12-03 02:44:33
I recently switched from using kqueue to GCD dispatch sources to monitor file changes. This has worked out well and resulted in a much simpler API. I documented my switch here . The only issue I have is that now I cannot access the flags on the event that I was able to in kqueue. For example with kqueue I was able to check if the file was deleted, renamed, or it's attributes were changed with the following: struct kevent event; ... if(event.flag & EV_DELETE) { printf("File was deleted\n"); } Is this API not available with GCD or do I need to set up dispatch sources up for each flag I would

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