grand-central-dispatch

Grand Central Dispatch without blocks

做~自己de王妃 提交于 2019-12-04 21:53:55
Is it possible to use GCD without blocks? Is there a way to use GCD using _f variant as mikeash says in his post . I searched around and there is no proof for either sides. is it possible or impossible. If its doable please give an example. /Selvin Of course it is possible! By _f variants Mike just mean set of GCD functions with _f suffix. They are alternatives for usual GCD functions but can accept a user defined function as a parameter instead of blocks. There are plenty of them: dispatch_async_f dispatch_sync_f dispatch_after_f dispatch_apply_f dispatch_group_async_f dispatch_group_notify_f

How can i download photos by order of cells in UITableView with dispatch_async?

旧城冷巷雨未停 提交于 2019-12-04 21:11:23
I have a UITableView that has photos, i get these photos from URLs and i use the block for downloading these photo asynchronously, and i want these photos be downloaded by order of the cells in the UITableView? // Download the images from the review of the businesses and put them into the "imageArray" dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://feature.site.com%@",entry.avatarUrl]]]; UIImage *imageField = [[UIImage alloc] initWithData:imageData]; dispatch

Difference between DispatchQueue types in swift

こ雲淡風輕ζ 提交于 2019-12-04 19:41:07
As I understand there are 3 types of DispatchQueue in swift: Main (serial) (Main Thread) Global (Concurrent) (Background Threads working in parallel) Custom (Concurrent or serial) And each one maybe work (asynch or synch) First question: Is it main queue working on UI thread only and not working on another thread? If the answer yes , how DispatchQueue.Main.async not blocking UI thread. If the answer No , what is the benefit of using DispatchQueue.global as long as DispatchQueue.Main.async work in another thread. Second question: what is deference between DispatchQueue.global (async) and

objc_release EXC_BAD_ACCESS

血红的双手。 提交于 2019-12-04 19:34:37
Unable to determine what is going on with this error. I am uploading a file in multiple segments. I have threaded my api calls into 7 concurrent threads. Here is the assembly code that it stops at. Here is my printed stack trace Finally the Stack window I do not have any DISPATCH_QUEUE_PRIORITY_LOW except for a #define for dispatch_get_low() and I do not have any calls to dispatch_get_low() as a little background, I am developing my app from xcode 4.4 and recently installed GM Seed 4.5 to test on ios 6. All of my code is still ios5 and this bug plagued me before and after the update of xcode.

How to achieve concurrent task through NSOperation? [closed]

天涯浪子 提交于 2019-12-04 19:33:43
I am new to NSoperation . NSoperation is a singleshot object. How can we achieve multiple operations concurrently through NSoperation ? is it possible without NSoperationQueue ? Even if we use NSoperationQueue, it will perform operations FIFO format.How will it execute Concurrently? If you want to implement a concurrent operation —that is, one that runs asynchronously with respect to the calling thread—you must write additional code to start the operation asynchronously. For example, you might spawn a separate thread, call an asynchronous system function, or do anything else to ensure that the

dispatch_async timeout method call

£可爱£侵袭症+ 提交于 2019-12-04 19:32:46
Is there a good way to call an external method after a set time limit for completing the long process outlined below? I would like the long process to stop trying after a set interval and call a method to try something else and wrap up the request. dispatch_async(dispatch_get_global_queue(0, 0), ^{ //// LONG PROCESS dispatch_async(dispatch_get_main_queue(), ^{ //// RESULTS PROCESS }); }); In order to "kill" the process that's running your block, you'll have to check a condition. This will allow you to do cleanup. Consider the following modifications: dispatch_async(dispatch_get_global_queue(0,

Grand Central Dispatch and unit testing

只愿长相守 提交于 2019-12-04 19:28:47
I have written a simple test case that follows Apple's documentation and I am not seeing the results that I'm expecting. Here's the code: - (void)testExample2 { NSLog(@"1"); dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"3"); dispatch_semaphore_signal(semaphore); }); NSLog(@"2"); dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); NSLog(@"4"); dispatch_release(semaphore); } I would expect to read: 1, 2, 3, 4 but instead my console just shows me 1, 3. I've been able to work around the issue using DISPATCH_TIME_NOW in a

GCD: How to remove waiting tasks from serial queue?

时光怂恿深爱的人放手 提交于 2019-12-04 18:46:05
问题 First I create a serial queue like this static dispatch_queue_t queue = dispatch_queue_create("myQueue", DISPATCH_QUEUE_SERIAL); then, at some unknown point in time a task gets added to the queue like this dispatch_async(queue, ^{ // do something, which takes some time }); If the first task hasn't finished yet, the new task will wait until the first completes (that's of course what a serial queue is for). But if I add 5 new tasks to the queue, while the original first one is still running, I

using the same dispatch queue in a method for background processing

十年热恋 提交于 2019-12-04 17:56:29
I have a method that updates two sections in a table that takes awhile. I want to do something like: dispatch_queue_t lowQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0); dispatch_queue_t mainQueue = dispatch_get_main_queue(); dispatch_async(lowQueue, ^{ NSArray *tempArray = // do long running task to get the data dispatch_async(mainQueue, ^{ // update the main thread [self.activityIndicatorView stopAnimating]; [self.reportsTableView reloadData]; }); }); dispatch_async(lowQueue, ^{ NSArray *tempArray2 = // same thing, do another long task // similarly, update the main thread

Swift 3 GCD lock variable and block_and_release error

人盡茶涼 提交于 2019-12-04 17:51:48
I am using Swift 3 GCD in order to perform some operations in my code. But I'm getting _dispatch_call_block_and_release error often. I suppose the reason behind this error is because different threads modify same variable, but I'm not sure how to fix problem. Here is my code and explanations: I have one variable which is accessed and modified in different threads: var queueMsgSent: Dictionary<Date,BTCommand>? = nil func lock(obj: AnyObject, blk:() -> ()) { objc_sync_enter(obj) blk() objc_sync_exit(obj) } func addMsgSentToQueue(msg: BTCommands) { if queueMsgSent == nil { queueMsgSent =