grand-central-dispatch

Using a single shared background thread for iOS data processing?

本小妞迷上赌 提交于 2019-12-04 12:57:35
问题 I have an app where I'm downloading a number of resources from the network, and doing some processing on each one. I don't want this work happening on the main thread, but it's pretty lightweight and low-priority, so all of it can really happen on the same shared work thread. That seems like it'd be a good thing to do, because of the work required to set up & tear down all of these work threads (none of which will live very long, etc.). Surprisingly, though, there doesn't seem to be a simple

libDispatch serving main queue without dispatch_main on Android

◇◆丶佛笑我妖孽 提交于 2019-12-04 12:30:32
I am using libDispatch (GCD) opensource on Android platform. So, most of the complex time consuming tasks are being done through NDK (where i am using libDispatch). For some calls, I am using dispatch_async(get_main_queue)...This is where the problem is coming... I am able to run tasks in the concurrent queues but not on main queue. Since this requires dispatch_main() to be called which we cannot do on here as Java thread will be blocked in that case. So, is it possible to run the Java UI on some secondary thread and hook the dispatch_main() to serve the dispatch_main_queue here? OR : Do I

Symbolic breakpoint for when dispatch_async is called with a specific queue

有些话、适合烂在心里 提交于 2019-12-04 12:25:55
I'm debugging an issue in my project involving grand central dispatch. In debugging this, it would be really helpful to have a way of being notified when work is dispatched to a specific queue. Is there some way of setting a symbolic breakpoint on dispatch_async with a condition that could check whether the dispatch queue argument is the same as some other queue that I have access to? Dave Lee Here's how to set a conditional breakpoint. (I haven't done conditions on queues, I'm making the assumption here that pointer equality will Just Work™.) First get the address of the queue you want, let's

In a UITableView, best method to cancel GCD operations for cells that have gone off screen?

我与影子孤独终老i 提交于 2019-12-04 12:18:59
问题 I have a UITableView that loads images from a URL into cells asynchronously using GCD. Problem is if a user flicks past 150 rows, 150 operations queue up and execute. What I want is to dequeue/cancel the ones that blew past and went off screen. How do I do this? My code at this point (pretty standard): - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath // after getting the cell... dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE

Realm write performed on background thread still blocks Main UI

血红的双手。 提交于 2019-12-04 10:59:34
问题 Periodically in my app, I need to perform large writes to Realm, anywhere between 100 to 10,000 objects. Obviously this is a large write, so I'm attempting to perform this write in the background so that the user can perform other operations and not even notice the write. Unfortunately, even though I thought my write was being performed on a background thread, the main UI still gets blocked. Here is the jist of the method that I call to perform the writes to realm. This method is called

Is there a queue dictionary for a GCD queue

六眼飞鱼酱① 提交于 2019-12-04 10:45:28
I am quite fond of the threadDictionary property in NSThread : very handy to store things with per-thread ownership. Is there an equivalent dictionary for a GCD queue? You might want to look into dispatch_set_context/dispatch_get_context . Documentation here and here . You have to manage the context but it might be what you're looking for. If you can target iOS 5 and above, you can use dispatch_queue_get[set]_specific() which allows you to add dictionary-style (i.e. keyed) values to a queue. I can't find the document pages on them, strangely enough, but they are commented in queue.h 来源: https:

Swift: Choose queue for Bluetooth Central manager

一曲冷凌霜 提交于 2019-12-04 09:56:28
I'm working on the app that will connect with a smart device via BLE and communicate with it. The question is: In what queue is the best practice to handle bluetooth events? I've read a lot of tutorials and in all of them I found this: centralManager = CBCentralManager(delegate: self, queue: nil) They choose to handle bluetooth events in main queue ( queue: nil ), but I suppose that it's not good practice. Because it could be a lot of queries send to peripheral device from central and a lot of answers send from peripheral to central. I assume this might be the reason of the app working slowly

How can I signal one thread to wait until a download is finished and after that pass the data to waiting thread

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 09:36:19
I have a singleton class to download some data from the web. I am calling the download method of the singleton class from other class 'A' inside a GCD Queue and the downloads starts. The same time I am also executing this download method from a class 'B' in a GCD Queue. In this situation I want to inform the Class 'B' to wait until the download is completed. And when the download is completed give a copy of the downloaded data to class 'B' also. Here I am trying to download the same file from two classes A and B, otherwise there is no problem in my implementation. How is it possible? Means

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

依然范特西╮ 提交于 2019-12-04 09:27:31
问题 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

Why is dispatch_sync on custom concurrent queue deadlocking

天涯浪子 提交于 2019-12-04 09:16:47
问题 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