SQLite User Forum

ThreadSantizer warning for sqlite3_enable_shared_cache()
Login
Hello. A random search lead me here, but I figured I can answer this for you since you haven't gotten a response...

The short answer is No.  ThreadSanitizer sees a data race and is reporting correctly, however, depending on the situation, that is okay.  It's not a false positive, but without the _Atomic keyword, it cannot make the assumption that the operation is indeed atomic.

A fix for this not to show up may require a mutex and locking.  This is a super expensive (relatively) change to something that *was* a single instruction, so there is a very real performance hit here.  It's really overkill to use a mutex here. 

When writing a threaded application, sometimes we need to access data that another thread may be writing to.  However, I may not care if I get the pre-updated value or the post-updated value.  The only thing I care is that it *is* one of them.  As long as the operation is atomic, I get what I want, however, by definition, it's still a race condition.

-Jason