grand-central-dispatch

What is the difference between GCD main queue and the main thread?

我们两清 提交于 2019-11-29 04:03:37
问题 I read comment on SO that dispatching a queue to the main thread is not the same as performing code on the main thread. If I understood correctly the user was saying that this dispatch_async(dispatch_get_main_queue(), ^{ // some code }); was not the same as this [self performSelectorOnMainThread:@selector(doStuff) withObject:nil waitUntilDone:NO]; - (void) doStuff { // some code } is there some true about this comment? Excluding the fact that the first code is asynchronous, for me, both codes

reusable multithread implementation in Sprite Kit

点点圈 提交于 2019-11-29 03:01:33
问题 I am working on a Sprite Kit game and I need to do some multithreading to maintain the healthy fps. On update I call a function to create a lot of UIBezierPaths and merge them using a C++ static library. If I have more than 10 shapes the frame rate drops dramatically so I decided I give GCD a try and try to solve the issue with a separate thread. I put this in didMoveToView: queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); and in the function that is being called on every

Applying Effect to iPhone Camera Preview “Video”

 ̄綄美尐妖づ 提交于 2019-11-29 01:57:20
问题 My goal is to write a custom camera view controller that: Can take photos in all four interface orientations with both the back and, when available, front camera. Properly rotates and scales the preview "video" as well as the full resolution photo. Allows a (simple) effect to be applied to BOTH the preview "video" and full resolution photo. Implementation (on iOS 4.2 / Xcode 3.2.5): Due to requirement (3), I needed to drop down to AVFoundation. I started with Technical Q&A QA1702 and made

Why NSOperationQueue is faster than GCD or performSelectorOnMainThread when they process a large number of tasks on the main Thread?

随声附和 提交于 2019-11-29 01:55:40
问题 for example, i have 100 times the for loop. and need to update UIImageView,and the last 2 method is same slowly. why? what is the different between they? //fastest [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [btnThumb setImage:[UIImage imageWithData:data] forState:UIControlStateNormal]; [scrollView addSubview:btnThumb]; }]; //slowly dispatch_async(dispatch_get_main_queue(), ^ { [btnThumb setImage:[UIImage imageWithData:data] forState:UIControlStateNormal]; [scrollView addSubview

cancel dispatch_after() method? [duplicate]

不打扰是莪最后的温柔 提交于 2019-11-29 01:02:37
This question already has an answer here: Prevent dispatch_after() background task from being executed 10 answers Is there a way to cancel dispatch_after() scheduled for some time in future, and haven't fired so far? I'm trying to make something like a scheduler for updates from server, and this method is just like I want, but, I'd love to cancel and re-schedule it at some point. Is it possible at all or I have to fallback and use NSTimer? There is NO way to prevent a dispatch_block from executing once it has been dispatch to it's queue, meaning that your dispatch_after cannot be canceled.

How do I kill/suspend/close an asyncronous block in GCD?

谁说我不能喝 提交于 2019-11-29 00:44:05
I've implemented a block that is dispatched asynchronously using GCD as follows: __block BOOL retValue; dispatch_async(dispatch_get_global_queue(0, 0), ^{ retValue = [self GCDHandler:actionName WithServiceType:serviceType :arguments]; }); return retValue; How do I cancel such a block if it is running for longer than I would like? Is there a way to cancel GCD-dispatched blocks, or provide a timeout to them? There is no built in way to cancel GCD blocks. They're rather set and forget. One way I've done this in the past is to provide 'tokens' for blocks. - (NSString*)dispatchCancelable:(dispatch

Unhiding a view is very slow in CTCallCenter callEventHandler

帅比萌擦擦* 提交于 2019-11-29 00:05:52
Reposting with more concise and focused question after original question went unanswered. Also adding more insight into the problem after another day of research: In my app delegate ( didFinishLaunching ), I set up a callEventHandler on CTCallCenter . The idea is that when a callState changes, I post a notification with a userInfo dict containing the call.callState . In my view, I observe this notification, and when the userInfo dict contains a value of CTCallDisconnected , I want to unhide a view. The problem I'm having is that the unhiding aspect is taking, almost consistenly, ~ 7 seconds.

Updating cell height after image downloads

三世轮回 提交于 2019-11-28 23:29:44
I am displaying some text and images in a UITableView . The image first gets downloaded. Since before the image gets downloaded, I don't know the size of image, so I initially put a UIImageView of some fixed size. And when the image is downloaded, I resize the UIImageView . dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // Download image dispatch_async(dispatch_get_main_queue(), ^{ // UIImageView resizing }); }); All this happens in cellForRowAtIndexPath . The issues I am facing here are : 1. How do I update the height of cell ? Considering that there can be

Simple GCD Serial Queue example like FIFO using blocks

◇◆丶佛笑我妖孽 提交于 2019-11-28 21:20:07
问题 I read Apple documentation on how to Use serial queues to ensure that tasks to execute in a predictable order but now i am confused too much. Some how i am able to work serially but still i am not clear so i need simple serial example for my methods to execute serially. I divided my functionality in to 4 parts and now want them to execute Serially [self ReadAllImagesFromPhotosLibrary]; [self WriteFewImagestoDirectory]; [self GettingBackAllImagesFromFolder]; [self MoveToNextView]; 回答1: To

dispatch_sync always scheduling a block on Main Thread

那年仲夏 提交于 2019-11-28 20:51:40
I am executing a block using dispatch_sync and the block is executed correctly. But this block is executed on the main thread. As per the Apple Doc: Serial queues (also known as private dispatch queues) execute one task at a time in the order in which they are added to the queue. The currently executing task runs on a distinct thread (which can vary from task to task) that is managed by the dispatch queue. which means (or what I understood) that current process that is being executed will run on a separate thread. Below is the code that I am using to judge what's going on. It is being called