title: FMDB with multithread problem
body: <p>In my ios app, I use FMDB to connect to the sqlite3 db.
  In the app, db will be used in multithread.As a result, I create a singleton in this way:</p>
  
  <pre><code>+ (id)instance
  {
  static DBManager *dbManager = nil;
  if (dbManager == nil) {
      dbManager = [[DBManager alloc]init];
  }
  
  [dbManager initialDBmanager];
  return dbManager;
  }
  </code></pre>
  
  <p>however Error: FMDataBase is currently in use , sometimes occures.
  then I update the instance:</p>
  
  <pre><code>+ (id)instance
  {
  static DBManager *dbManager = nil;
  if (dbManager == nil) {
      dbManager = [[DBManager alloc]init];
              [dbManager initialDBmanager];
  }
  
  while([dbManager.db inUse])//In my opinion this promises the db is free
      {
      }
  return dbManager;
  }
  </code></pre>
  
  <p>The Error still exists.
  So My question is how to correctly create a singleton and why the code can't avoid the error.
  thanks!</p>