title: Singleton class vs. class with static member
body: <p>Despite the many threads on that topic, I am still unclear as to when to choose which approach.
  I am hoping that by discussing a specific example, I will finally "get it."</p>
  
  <p>Note: My language here is Cocoa though the general issue is not language-specific.</p>
  
  <p>I have a class TaskQueue that I want to use to:  </p>
  
  <ul>
  <li>access from anywhere in my code in order to add or remove scheduled tasks</li>
  <li>process automatically the scheduled tasks at regular intervals</li>
  </ul>
  
  <p>When TaskQueue is first used, I want TaskQueue to initiate a thread that will then wake up at regular intervals to process the tasks.</p>
  
  <p>Obviously, I will need at a minimum two variables:  </p>
  
  <ul>
  <li>an array to store the tasks  </li>
  <li>an instance of the thread processing the tasks  </li>
  </ul>
  
  <p>Since I only want one queue of tasks and one thread to process these tasks, I have two choices:</p>
  
  <ol>
  <li><p>Make TaskQueue a singleton class (using for example CWL_DECLARE_SINGLETON_FOR_CLASS_WITH_ACCESSOR as described in <a href="http://www.cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html" rel="nofollow noreferrer">http://www.cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html</a>, which I believe I will have to modify the CWLSynthesizeSingleton.h file to start the thread at init time.)</p></li>
  <li><p>Have the array of tasks and the thread instance both be static (following the approach suggested here: <a href="https://stackoverflow.com/questions/695980/how-do-i-declare-class-level-properties-in-objective-c">How do I declare class-level properties in Objective-C?</a>)</p></li>
  </ol>
  
  <p>Is there clearly one approach that's better than the other one in this specific case?  If so, why?</p>