[Solved] GCD flow how to write


dispatch_release(queue); don’t do it there, the dispatch queue that you are calling its going to a backThread, so wat is happening is :-

your queue is getting released before the block of code executes.

since your queue looks like an ivar, release it in dealloc. Rest, your code looks fine ..put a breakpoint inside and check if the block is executing.

EDIT

I dont understand, what u are trying to achieve by suspending the queue, there is no need to do it. You dont need to check whether the block has finished executing. The block will finish and then call the dispatch_async , get the main queue and update the UI from there.

Now, when you are creating the queue, create it lazily in your method. take the queue as an ivar in header file:

@interface YourFileController : UIViewController {
    dispatch_queue_t queue;
}

Then in your method modify it as such:

if (isCaptureScreenStart)
{
    if (CMTimeGetSeconds([avPlayer currentTime])>0)
    {
        if (avFramesArray!=nil)
        {
            if (!queue)
                queue = dispatch_queue_create("array", DISPATCH_QUEUE_SERIAL);

            dispatch_sync(queue, ^{
                [avFramesArray addObject:[self screenshotFromPlayer:avPlayer maximumSize:avPlayerLayer.frame.size :CMTimeGetSeconds([avPlayer currentTime])]];//stop at this line
                NSLog(@"count:%d",[avFramesArray count]);
                dispatch_sync(dispatch_get_main_queue(), ^{
                    NSLog(@"Frame are created:%d",[avFramesArray count]);
                    if ([avFramesArray count]==0)    
                    {
                        NSLog(@"Frame are over");
                    }
                });
            });
        }
    }
}

NOTE : DISPATCH_QUEUE_SERIAL creates a serial queue, meaning all the blocks submitted to it will execute serially in First in First Out order. Once all the blocks submitted get executed, the queue stays 😉 ..submit another block to it and it executes the block 😀

this represents one whole block:-

[avFramesArray addObject:[self screenshotFromPlayer:avPlayer maximumSize:avPlayerLayer.frame.size :CMTimeGetSeconds([avPlayer currentTime])]];//stop at this line
                NSLog(@"count:%d",[avFramesArray count]);
                dispatch_sync(dispatch_get_main_queue(), ^{
                    NSLog(@"Frame are created:%d",[avFramesArray count]);
                    if ([avFramesArray count]==0)    
                    {
                        NSLog(@"Frame are over");
                    }
                });

7

solved GCD flow how to write