I define a property that returns a serial dispatch queue using lazy instantiation, something like this:
@property (nonatomic, readonly) dispatch_queue_t queue;
- (dispatch_queue_t)queue
{
if (!_queue) {
_queue = dispatch_queue_create("com.example.MyQueue", NULL);
}
return _queue;
}
Then let's say that I define an action method for some button that adds a block to the queue:
- (IBAction)buttonTapped:(UIButton *)sender
{
dispatch_async(self.queue, ^{
printf("Do some work here.\n");
});
}
The code for the actual method is more involved than a simple print statement, but this will do for the example.
So far so good. However, if I build and run the program, I can tap on the button 10 times and see the block run, but when I tap an eleventh time, the program hangs.
If I change the serial queue to a concurrent queue, no problems. I can dispatch as many blocks to the queue as I like.
Any idea what might be going on? Is there a limit to the number of blocks that can be posted to a serial queue?