jdewind / JSGCDDispatcher

A small Objective-C wrapper around GCD
MIT License
30 stars 5 forks source link

How can I dealloc a suspended serial queue? #1

Open lexrus opened 12 years ago

lexrus commented 12 years ago

It will cause a exception.

jdewind commented 12 years ago

The proper way of releasing a queue is done via dispatch_release

For example,

dispatch_release( serial_queue )

Is this what you are doing?

lexrus commented 12 years ago

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?

jdewind commented 12 years ago

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?

lexrus commented 12 years ago
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;