JSGCDDispatcher icon indicating copy to clipboard operation
JSGCDDispatcher copied to clipboard

How can I dealloc a suspended serial queue?

Open lexrus opened this issue 13 years ago • 4 comments

It will cause a exception.

lexrus avatar Jun 08 '12 15:06 lexrus

The proper way of releasing a queue is done via dispatch_release

For example,

dispatch_release( serial_queue )

Is this what you are doing?

jdewind avatar Jun 08 '12 15:06 jdewind

Hi, @dewind Thank you for your reply. Yes, if the serial_queue is suspended previously then there will be a EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP...) exception. Maybe I should turn back to NSOperation so that I can stop and cancel my queue?

lexrus avatar Jun 08 '12 16:06 lexrus

That is is interesting and would appear to be a bug if one can't deallocate a suspended queue. Do you have a snippet of code you'd be willing to provide?

jdewind avatar Jun 08 '12 22:06 jdewind

JSGCDDispatcher *downloadQueue = [JSGCDDispatcher dispatcherWithSerialQueueID:issuesDownloadQueueID];
for (uint i = 0; i < 20; i++) {
    [downloadQueue dispatchOnSerialQueue:^{
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://yahoo.com"]];
        [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        NSLog(@"downloaded");
    }];
}
[downloadQueue submitSerialQueueCompletionListener:^{
    NSLog(@"download queue complete");
}];

[downloadQueue suspendSerialQueue];
downloadQueue = nil;

lexrus avatar Jun 09 '12 05:06 lexrus