Index: src/mutex_unix.c ================================================================== --- src/mutex_unix.c +++ src/mutex_unix.c @@ -91,10 +91,11 @@ void sqlite3MemoryBarrier(void){ #if defined(SQLITE_MEMORY_BARRIER) SQLITE_MEMORY_BARRIER; #elif defined(__GNUC__) && GCC_VERSION>=4001000 __sync_synchronize(); +# define sqlite3MemoryBarrier_IS_RELIABLE 1 #endif } /* ** Initialize and deinitialize the mutex subsystem. Index: src/mutex_w32.c ================================================================== --- src/mutex_w32.c +++ src/mutex_w32.c @@ -85,12 +85,14 @@ void sqlite3MemoryBarrier(void){ #if defined(SQLITE_MEMORY_BARRIER) SQLITE_MEMORY_BARRIER; #elif defined(__GNUC__) __sync_synchronize(); +# define sqlite3MemoryBarrier_IS_RELIABLE 1 #elif MSVC_VERSION>=1300 _ReadWriteBarrier(); +# define sqlite3MemoryBarrier_IS_RELIABLE 1 #elif defined(MemoryBarrier) MemoryBarrier(); #endif } Index: src/os_unix.c ================================================================== --- src/os_unix.c +++ src/os_unix.c @@ -4891,12 +4891,14 @@ UNUSED_PARAMETER(fd); sqlite3MemoryBarrier(); /* compiler-defined memory barrier */ assert( fd->pMethods->xLock==nolockLock || unixFileMutexNotheld((unixFile*)fd) ); +#ifndef sqlite3MemoryBarrier_IS_RELIABLE unixEnterMutex(); /* Also mutex, for redundancy */ unixLeaveMutex(); +#endif } /* ** Close a connection to shared-memory. Delete the underlying ** storage if deleteFlag is true. Index: src/os_win.c ================================================================== --- src/os_win.c +++ src/os_win.c @@ -4172,12 +4172,14 @@ static void winShmBarrier( sqlite3_file *fd /* Database holding the shared memory */ ){ UNUSED_PARAMETER(fd); sqlite3MemoryBarrier(); /* compiler-defined memory barrier */ +#ifndef sqlite3MemoryBarrier_IS_RELIABLE winShmEnterMutex(); /* Also mutex, for redundancy */ winShmLeaveMutex(); +#endif } /* ** This function is called to obtain a pointer to region iRegion of the ** shared-memory associated with the database file fd. Shared-memory regions