I have 10 instances of a class that should perform some background tasks. This should occur sequentially for instances, but may be concurrent with respect to the fact that instances can perform work independently of each other.
What is the most cost-effective in terms of speed and battery? When do I need to worry about creating too many queues?
This one (A)?
- (dispatch_queue_t)queue { static dispatch_queue_t queue; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ queue = dispatch_queue_create("no.agens.someclass.somequeue", DISPATCH_QUEUE_SERIAL); }); return queue; }
Or this one (B)?
// assume read-only property of 'queue' is defined - (dispatch_queue_t)queue { if(_queue == nil) { _queue = dispatch_queue_create("no.agens.someclass.somequeue", DISPATCH_QUEUE_SERIAL); } return _queue; }
source share