grand-central-dispatch

Strong dispatch_queue_t in CocoaPods library

不打扰是莪最后的温柔 提交于 2020-01-13 19:41:30
问题 In a library that may be built with an iOS 5.x/OS X 10.7 deployment target or with a newer one I had a problem for properly defining a dispatch_queue_t property. For the most part I could solve it as suggested here: #if OS_OBJECT_HAVE_OBJC_SUPPORT // == 1 not really needed @property (nonatomic, strong) dispatch_queue_t loggerQueue; // An Objective-C object #else @property (nonatomic, assign) dispatch_queue_t loggerQueue; // A C pointer #endif This works when manually creating a static library

libDispatch serving main queue without dispatch_main on Android

早过忘川 提交于 2020-01-13 05:00: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

Sync dispatch on current queue

自作多情 提交于 2020-01-12 19:08:47
问题 I know you might find this an odd question, but I'm just learning GCD and I want to fully understand all its aspects. So here it is: Is there ever any reason to dispatch a task SYNC on the CURRENT QUEUE? For example: dispatch_queue_t concurrentQueue = dispatch_get_global_queue(...); dispatch_async(concurrentQueue, ^{ //this is work task 0 //first do something here, then suddenly: dispatch_sync(concurrentQueue, ^{ //work task 1 }); //continue work task 0 }); I understand one thing: if instead

iOS - swift 3 - DispatchGroup

心已入冬 提交于 2020-01-11 12:04:59
问题 I created this basic architecture to handle my networking stuff, i wanted to keep it modular and structured: public class NetworkManager { public private(set) var queue: DispatchQueue = DispatchQueue(label: "com.example.app.dispatchgroups", attributes: .concurrent, target: .main) public private(set) var dispatchGroup: DispatchGroup = DispatchGroup() private static var sharedNetworkManager: NetworkManager = { let networkManager = NetworkManager() return networkManager }() private init() {}

iOS - swift 3 - DispatchGroup

元气小坏坏 提交于 2020-01-11 12:04:22
问题 I created this basic architecture to handle my networking stuff, i wanted to keep it modular and structured: public class NetworkManager { public private(set) var queue: DispatchQueue = DispatchQueue(label: "com.example.app.dispatchgroups", attributes: .concurrent, target: .main) public private(set) var dispatchGroup: DispatchGroup = DispatchGroup() private static var sharedNetworkManager: NetworkManager = { let networkManager = NetworkManager() return networkManager }() private init() {}

How to use dispatch_queue_set_specific() and dispatch_get_specific()

泪湿孤枕 提交于 2020-01-09 15:23:51
问题 I'm having a hard time finding good examples on how to use these functions. static void * kQueue1Key = "key1"; static void * kQueue2Key = "key2"; dispatch_queue_t queue1 = dispatch_queue_create("com.company.queue1", DISPATCH_QUEUE_SERIAL); dispatch_queue_t queue2 = dispatch_queue_create("com.company.queue2", DISPATCH_QUEUE_SERIAL); dispatch_queue_set_specific(queue1, kQueue1Key, (void *)kQueue1Key, NULL); dispatch_queue_set_specific(queue2, kQueue2Key, (void *)kQueue2Key, NULL); dispatch_sync

How to use dispatch_queue_set_specific() and dispatch_get_specific()

▼魔方 西西 提交于 2020-01-09 15:22:13
问题 I'm having a hard time finding good examples on how to use these functions. static void * kQueue1Key = "key1"; static void * kQueue2Key = "key2"; dispatch_queue_t queue1 = dispatch_queue_create("com.company.queue1", DISPATCH_QUEUE_SERIAL); dispatch_queue_t queue2 = dispatch_queue_create("com.company.queue2", DISPATCH_QUEUE_SERIAL); dispatch_queue_set_specific(queue1, kQueue1Key, (void *)kQueue1Key, NULL); dispatch_queue_set_specific(queue2, kQueue2Key, (void *)kQueue2Key, NULL); dispatch_sync

Stop a DispatchQueue that is running on the main thread

孤人 提交于 2020-01-09 10:52:28
问题 I have this block of code: DispatchQueue.main.asyncAfter(deadline: .now() + (delay * Double(isDelayAccounted.hashValue)) + extraDelay) { self.isShootingOnHold = false self.shoot() self.shootingEngine = Timer.scheduledTimer(timeInterval: (Double(60)/Double(self.ratePerMinute)), target: self, selector: #selector(ShootingEnemy.shoot), userInfo: nil, repeats: true) } Now, I want to be able to stop this thread from executing. How can I stop it from being executed? For instance, after 3 seconds, I

UIWebView stringByEvaluatingJavaScriptFromString hangs on iOS5.0/5.1 when called using GCD

元气小坏坏 提交于 2020-01-09 10:22:28
问题 I have the following code in viewDidLoad , which works properly on iOS 4.3, but it hangs on iOS 5/5.1. On iOS 5/5.1, the alert dialog is shown but can not be dismissed, the UI thread freezes, the OK button just can not be clicked. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_sync(dispatch_get_main_queue(), ^{ [self.webview stringByEvaluatingJavaScriptFromString:@"alert('HELLO WORLD!')"]; }); }); Is this a bug? 回答1: After test, I consider it as a

UIWebView stringByEvaluatingJavaScriptFromString hangs on iOS5.0/5.1 when called using GCD

半世苍凉 提交于 2020-01-09 10:22:28
问题 I have the following code in viewDidLoad , which works properly on iOS 4.3, but it hangs on iOS 5/5.1. On iOS 5/5.1, the alert dialog is shown but can not be dismissed, the UI thread freezes, the OK button just can not be clicked. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_sync(dispatch_get_main_queue(), ^{ [self.webview stringByEvaluatingJavaScriptFromString:@"alert('HELLO WORLD!')"]; }); }); Is this a bug? 回答1: After test, I consider it as a