SQLite Forum

DATA RACE 2: Found in sqlite3.c
Login
Your analysis is incorrect.

This is no code path that reaches line sqlite3.c:37305 
with pShmNode->pShmMutex uninitialized in a thread-safe
build.  Every path to sqlite3.c:37305 must traverse this code:

~~~~~
  unixEnterMutex();
  pInode = pDbFd->pInode;
  pShmNode = pInode->pShmNode;
  if( pShmNode==0 ){
    /*...*/
    if( sqlite3GlobalConfig.bCoreMutex ){
      pShmNode->pShmMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
    }
    /*...*/
  }
  unixLeaveMutex();
~~~~~

Assuming the `sqlite3GlobalConfig.bCoreMutex` global variable is true,
that means that `pShmNode->pShmMutex` must be initialized prior to use.

Your tool is perhaps confused because it assumes that
`sqlite3GlobalConfig.bCoreMutex` might be false.  But that is only
true if SQLite is running in "[single-threaded mode][1]".

I suppose your tool is technically correct - there is a data race
if you have configured SQLite for single-threaded mode.  But that
does not really count, since the documentation clearly states that
in single-threaded mode, SQLite is not threadsafe.

[1]: https://www.sqlite.org/threadsafe.html