Creating a Grand Central Dispatch queue for a specific singleton
I have a singleton tha开发者_如何学Got I use for creating an application wide report. As data is passed to the singleton by the application the singleton then formats the data for use in the report. I use Grand Central Dispatch so that the report creation is not on the main thread.
My question is, would it be bad practise to create a Grand Central Dispatch queue when the singleton is initialised that is then only used by the singleton. I'd like a single thread to be associated with the singleton because if I don't some parts of the report are prone to get out of sync breaking the formatting of the report. If this is bad practise then what other pattern would be suitable for this problem but giving me quick and easy to use code.
Your approach is the right one. Serial dispatch queues are meant for synchronizing access to a particular resource. They process requests FIFO which makes them suitable for your requirement. I don't think the singleton
part figures as much here.
精彩评论