title: Thread safe instantiation of a singleton
body: <p>Which one synchronization method to use to ensure a singleton remains a singleton?</p>
  
  <pre><code>+(Foo*)sharedInstance
  {
     @synchronized(self)
     {
        if (nil == _sharedInstance)
        {
           _sharedInstance = [[Foo alloc] init];
           ...
        }
     }
     return _sharedInstance;
  }
  </code></pre>
  
  <p>or using a mutex?</p>
  
  <pre><code>#import &lt;pthread.h&gt;
  
  static pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
  
  +(Foo*)sharedInstance
  {
     pthread_mutex_lock(&amp;_mutex);
     if (nil == _sharedInstance)
     {
        _sharedInstance = [[Foo alloc] init];
        ...
     }
     pthread_mutex_unlock(&amp;_mutex);
     return _sharedInstance;
  }
  </code></pre>
  
  <p>Hmmm.. any comments on this?</p>