Remove the SQLITE_MUTEX_APPDEF compile-time option.  The SQLITE_THREADSAFE=0
option always removes all mutex code.  For application-defined mutexes only,
use SQLITE_THREADSAFE=1 with SQLITE_MUTEX_NOOP=1.  Ticket #3421. (CVS 5779)

FossilOrigin-Name: 02a12eb1cfe9307c66556105a1a99d657cc01ab5
diff --git a/Makefile.in b/Makefile.in
index b27bdb8..a556df1 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -160,7 +160,7 @@
         delete.lo expr.lo fault.lo func.lo global.lo \
         hash.lo journal.lo insert.lo legacy.lo loadext.lo \
         main.lo malloc.lo mem1.lo mem2.lo mem3.lo mem4.lo mem5.lo mem6.lo \
-        mutex.lo mutex_os2.lo mutex_unix.lo mutex_w32.lo \
+        mutex.lo mutex_noop.lo mutex_os2.lo mutex_unix.lo mutex_w32.lo \
         opcodes.lo os.lo os_unix.lo os_win.lo os_os2.lo \
         pager.lo parse.lo pcache.lo pragma.lo prepare.lo printf.lo random.lo \
         resolve.lo select.lo status.lo \
@@ -217,6 +217,7 @@
   $(TOP)/src/mem6.c \
   $(TOP)/src/mutex.c \
   $(TOP)/src/mutex.h \
+  $(TOP)/src/mutex_noop.c \
   $(TOP)/src/mutex_os2.c \
   $(TOP)/src/mutex_unix.c \
   $(TOP)/src/mutex_w32.c \
@@ -572,6 +573,9 @@
 mutex.lo:	$(TOP)/src/mutex.c $(HDR)
 	$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mutex.c
 
+mutex_noop.lo:	$(TOP)/src/mutex_noop.c $(HDR)
+	$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mutex_noop.c
+
 mutex_os2.lo:	$(TOP)/src/mutex_os2.c $(HDR)
 	$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/mutex_os2.c
 
diff --git a/main.mk b/main.mk
index 92903ec..50d9962 100644
--- a/main.mk
+++ b/main.mk
@@ -54,7 +54,7 @@
          expr.o fault.o func.o global.o hash.o \
          icu.o insert.o journal.o legacy.o loadext.o \
          main.o malloc.o mem1.o mem2.o mem3.o mem4.o mem5.o mem6.o \
-         mutex.o mutex_os2.o mutex_unix.o mutex_w32.o \
+         mutex.o mutex_noop.o mutex_os2.o mutex_unix.o mutex_w32.o \
          opcodes.o os.o os_os2.o os_unix.o os_win.o \
          pager.o parse.o pcache.o pragma.o prepare.o printf.o \
          random.o resolve.o rtree.o select.o status.o \
@@ -102,6 +102,7 @@
   $(TOP)/src/mem6.c \
   $(TOP)/src/mutex.c \
   $(TOP)/src/mutex.h \
+  $(TOP)/src/mutex_noop.c \
   $(TOP)/src/mutex_os2.c \
   $(TOP)/src/mutex_unix.c \
   $(TOP)/src/mutex_w32.c \
diff --git a/manifest b/manifest
index 41fb8ed..6263bc4 100644
--- a/manifest
+++ b/manifest
@@ -1,7 +1,7 @@
-C Fix\sa\srecently\sintroduced\stest\sscript\sbug\scausing\srollback.test\sto\sthrow\san\sexception\swhen\srun\susing\sthe\s"onefile"\svariation.\s(CVS\s5778)
-D 2008-10-07T15:00:09
+C Remove\sthe\sSQLITE_MUTEX_APPDEF\scompile-time\soption.\s\sThe\sSQLITE_THREADSAFE=0\noption\salways\sremoves\sall\smutex\scode.\s\sFor\sapplication-defined\smutexes\sonly,\nuse\sSQLITE_THREADSAFE=1\swith\sSQLITE_MUTEX_NOOP=1.\s\sTicket\s#3421.\s(CVS\s5779)
+D 2008-10-07T15:25:48
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
-F Makefile.in e4ab842f9a64ef61d57093539a8aab76b12810db
+F Makefile.in 7fc26e087207e7a4a7723583dbd7997477af3b13
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
 F README b974cdc3f9f12b87e851b04e75996d720ebf81ac
 F VERSION 708c93c5dbb97b8a8e4c39eb77c53dae43d96910
@@ -79,7 +79,7 @@
 F ext/rtree/viewrtree.tcl 09526398dae87a5a87c5aac2b3854dbaf8376869
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
 F ltmain.sh 09fe5815427dc7d0abb188bbcdf0e34896577210
-F main.mk b207901cca3301dcb08892be8563eab126f10037
+F main.mk 5fc368ed5b618cc1713b7480a03346998719def4
 F mkdll.sh 79d1ed6ae221c10589dd969f130f8a3cccfffbb7
 F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
 F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
@@ -98,7 +98,7 @@
 F src/attach.c db3f4a60538733c1e4dcb9d0217a6e0d6ccd615b
 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
 F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
-F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53
+F src/btmutex.c 3a90096c3080b9057dc570b8e16e46511e1c788a
 F src/btree.c 64a38df6f0a9997563418ed194984b81e4ab3694
 F src/btree.h 6371c5e599fab391a150c96afbc10062b276d107
 F src/btreeInt.h e38e9b2b285f40f5bc0a6664f630d4a141622f16
@@ -117,8 +117,8 @@
 F src/insert.c 110cca7845ed5a66c08fdd413b02e706ae34455f
 F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
 F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3
-F src/loadext.c 6581a5bbc4d74fcd46dbbcfd695a6a5417f778a2
-F src/main.c 9c9cad9d93f9e5023f4688bb77e10a5949632305
+F src/loadext.c cadd5df14bcda5ef0c26d815eb609a755861923e
+F src/main.c 48e2ff96b1e6efdc144f4bcaa737621f7273a3b1
 F src/malloc.c 31f4ca218f4b664dce45ef9c4f1fcd2929c67a42
 F src/mem1.c 5a529ff121c55ab067be14de00f86f6dcc4f4fb9
 F src/mem2.c f87e681d0d1ed8436870d089332ed0d27d885b5c
@@ -126,12 +126,13 @@
 F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909
 F src/mem5.c 706d462c13a9819dfec7c10d9dccedf8d199960c
 F src/mem6.c febe4db9ddef73df500989e68a9d4ac68602a075
-F src/mutex.c 81174f600553c25832e9a8705b609f16c73a4c01
-F src/mutex.h e52ffa1dfc6a6077e8b1823d2c2b7dfcbcf85594
+F src/mutex.c e9cb5fbe94afb4328869afaf3ac49bd1327559eb
+F src/mutex.h 9e686e83a88838dac8b9c51271c651e833060f1e
+F src/mutex_noop.c 5356c291c6c58c09163888d2116f830468cd8157
 F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97
 F src/mutex_unix.c 29049a61755cccddb2ee53904e6906bb7674223c
 F src/mutex_w32.c f0d21ff1f6981e5aedc56796adf3a347423ef736
-F src/os.c 74ac327e8f82f53c9461466f46f736ac5d05b97e
+F src/os.c 0b411644b87ad689d7250bbfd1834d99b81a3df4
 F src/os.h ef8abeb9afc694b82dbd169a91c9b7e26db3c892
 F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
 F src/os_os2.c e391fc95adc744bbdcefd4d11e3066998185a0a0
@@ -145,13 +146,13 @@
 F src/pragma.c 0b1c2d2a241dd79a7361bbeb8ff575a9e9d7cd71
 F src/prepare.c c7e00ed1b0bdcf699b1aad651247d4dc3d281b0b
 F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d
-F src/random.c 11bbdf7def3746a762fbdb56c9d04648135ad6d8
+F src/random.c a87afbd598aa877e23ac676ee92fd8ee5c786a51
 F src/resolve.c 1971ff6996f1a73303339acf7f1de8497546045d
 F src/select.c c1c555ee714c61db92b2688b307a0145d7405122
 F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967
 F src/sqlite.h.in ea235b37a691b32e7941baa70fb0afaf6377dbb4
 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
-F src/sqliteInt.h 78ec9e3cd535c8a092d6b19808c5ffb5276381f0
+F src/sqliteInt.h d7d1c122acd525994d7a69f0ce521626473bf9f0
 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
 F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
 F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
@@ -168,7 +169,7 @@
 F src/test_async.c 45024094ed7cf780c5d5dccda645145f95cf78ef
 F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
 F src/test_btree.c d7b8716544611c323860370ee364e897c861f1b0
-F src/test_config.c db72e95bafdd53c05ceb8735f833cc5dc1f48782
+F src/test_config.c f995f649dc2dc8173079d613694b29b0b3b5f84b
 F src/test_devsym.c 802d10e65b4217208cb47059b84adf46318bcdf4
 F src/test_func.c a55c4d5479ff2eb5c0a22d4d88e9528ab59c953b
 F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
@@ -182,7 +183,7 @@
 F src/test_server.c f0a403b5f699c09bd2b1236b6f69830fd6221f6b
 F src/test_tclvar.c 9e42fa59d3d2f064b7ab8628e7ab2dc8a9fe93d4
 F src/test_thread.c d74fc445e0dba0e00806117eb449b307c0b146bf
-F src/test_wsd.c a36c7fbb93eebf7c917d00fcaab25ad4d8a7918b
+F src/test_wsd.c c297d7d6b8a990239e1bd25935e81d612d8ae31d
 F src/tokenize.c aaa5fa6a4536a9dd7c855a3f66f32508f1612138
 F src/trigger.c 649940b5bf5838a33721fb72372e7c9d1faf56a9
 F src/update.c 206fffc877379affe3a9b42c78e478ea0874c9fe
@@ -192,7 +193,7 @@
 F src/vdbe.c c9499f1824049cfef00a6146ef832b742f477920
 F src/vdbe.h 41c99aaad9167c1b5431993db446de74b2f71fc3
 F src/vdbeInt.h b48c74d86a9fb62b707a3186ccca76bb32f1c6be
-F src/vdbeapi.c 319d3be8a309ecbadcdb21c3b73b158d8505ca1d
+F src/vdbeapi.c 8f194355e0270f236838d5b2a3af3ae3572adf44
 F src/vdbeaux.c 20a7d109c95e32beee7891fba828c63e419af26c
 F src/vdbeblob.c b0dcebfafedcf9c0addc7901ad98f6f986c08935
 F src/vdbefifo.c 20fda2a7c4c0bcee1b90eb7e545fefcdbf2e1de7
@@ -442,8 +443,8 @@
 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
 F test/misc7.test 0d763f703a34521e55ab30145b747aafa0e5f794
 F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
-F test/mutex1.test dbcf556502389abcca65a80af45b80c141714ccc
-F test/mutex2.test 56f282f436596e9febdc6e0db2c507432b6724bb
+F test/mutex1.test ff260ddaf7240390dbb013d28aba3a33ec0dada4
+F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
 F test/nan.test c627d79b3d36ea892563fd67584b3e8a18f0618a
 F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
 F test/null.test a8b09b8ed87852742343b33441a9240022108993
@@ -513,11 +514,11 @@
 F test/tempdb.test b88ac8a19823cf771d742bf61eef93ef337c06b1
 F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125
 F test/tester.tcl 12fd8394caeb71f7d961707da8668756389bc9d3
-F test/thread001.test 3fb08080e1fe84d1bb7ec7bbc9e13743a77e5bc5
-F test/thread002.test ed9b800460df01e3cf9428ee11dc4e3f04b9b896
-F test/thread003.test 047fb3b971f5dac856d34394186bf8a4bdd39e3e
-F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
-F test/thread2.test 6d7b30102d600f51b4055ee3a5a19228799049fb
+F test/thread001.test dda1d39cea954d7d43f520891d77a93d3325ab58
+F test/thread002.test 84c03a9fc4f7a5f92eefe551266afa840c2eb6ae
+F test/thread003.test e17754799649c2b732c295620dca041c32f01e16
+F test/thread1.test 862dd006d189e8b0946935db17399dcac2f8ef91
+F test/thread2.test 91f105374f18a66e73a3254c28fe7c77af69bdea
 F test/thread_common.tcl 8a9d7a4500dfdbbd36679c977831b62c130b76b1
 F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
 F test/threadtest2.c ace893054fa134af3fc8d6e7cfecddb8e3acefb9
@@ -625,7 +626,7 @@
 F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf
 F tool/mkkeywordhash.c c219ee2b8b5b8e7011cccfa1caec62d9812e82e7
 F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x
-F tool/mksqlite3c.tcl 50f3ca0333694ef51ae4016c310af020c09006f4
+F tool/mksqlite3c.tcl f74c5aacea1668dcf4ac0b75f3e1830942b733f6
 F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87
 F tool/omittest.tcl 4be55add3ec87f45fe041b7bfa8f16dab8105431
 F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
@@ -640,7 +641,7 @@
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 6b7c8d56403f6b9b88b8494c86f3d62e487cb2ac
-R 7cd13133ce43d0c91945e4ca0e25fbf9
-U danielk1977
-Z 9910f1e63988d37770e2ba91816affea
+P 7d55ec374d62c6d3d588949b96e194920083fe4e
+R 1635239c5f5cf9fdcf5c2cf2ba05eee1
+U drh
+Z 038b5cd7b8b898745d7ab0f99c550ee3
diff --git a/manifest.uuid b/manifest.uuid
index 7d434d5..16e1c27 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-7d55ec374d62c6d3d588949b96e194920083fe4e
\ No newline at end of file
+02a12eb1cfe9307c66556105a1a99d657cc01ab5
\ No newline at end of file
diff --git a/src/btmutex.c b/src/btmutex.c
index bf63617..6c3fd5d 100644
--- a/src/btmutex.c
+++ b/src/btmutex.c
@@ -10,7 +10,7 @@
 **
 *************************************************************************
 **
-** $Id: btmutex.c,v 1.10 2008/07/14 19:39:17 drh Exp $
+** $Id: btmutex.c,v 1.11 2008/10/07 15:25:48 drh Exp $
 **
 ** This file contains code used to implement mutexes on Btree objects.
 ** This code really belongs in btree.c.  But btree.c is getting too
@@ -61,7 +61,6 @@
   p->wantToLock++;
   if( p->locked ) return;
 
-#ifndef SQLITE_MUTEX_NOOP
   /* In most cases, we should be able to acquire the lock we
   ** want without having to go throught the ascending lock
   ** procedure that follows.  Just be sure not to block.
@@ -93,7 +92,6 @@
       pLater->locked = 1;
     }
   }
-#endif /* SQLITE_MUTEX_NOOP */
 }
 
 /*
diff --git a/src/loadext.c b/src/loadext.c
index d3eee96..47258c7 100644
--- a/src/loadext.c
+++ b/src/loadext.c
@@ -12,7 +12,7 @@
 ** This file contains code used to dynamically load extensions into
 ** the SQLite library.
 **
-** $Id: loadext.c,v 1.54 2008/09/02 00:52:52 drh Exp $
+** $Id: loadext.c,v 1.55 2008/10/07 15:25:48 drh Exp $
 */
 
 #ifndef SQLITE_CORE
@@ -273,7 +273,7 @@
   sqlite3_file_control,
   sqlite3_memory_highwater,
   sqlite3_memory_used,
-#ifdef SQLITE_MUTEX_NOOP
+#ifdef SQLITE_MUTEX_OMIT
   0, 
   0, 
   0,
@@ -502,7 +502,7 @@
 #endif
   {
     int i;
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
     sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
     wsdAutoextInit;
@@ -536,7 +536,7 @@
   if( sqlite3_initialize()==SQLITE_OK )
 #endif
   {
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
     sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
     wsdAutoextInit;
@@ -564,7 +564,7 @@
   }
   for(i=0; go; i++){
     char *zErrmsg = 0;
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
     sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
     sqlite3_mutex_enter(mutex);
diff --git a/src/main.c b/src/main.c
index eece6f1..12b98c0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.502 2008/09/23 17:39:26 danielk1977 Exp $
+** $Id: main.c,v 1.503 2008/10/07 15:25:48 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -245,6 +245,11 @@
 
   va_start(ap, op);
   switch( op ){
+
+    /* Mutex configuration options are only available in a threadsafe
+    ** compile. 
+    */
+#if SQLITE_THREADSAFE
     case SQLITE_CONFIG_SINGLETHREAD: {
       /* Disable all mutexing */
       sqlite3GlobalConfig.bCoreMutex = 0;
@@ -264,6 +269,19 @@
       sqlite3GlobalConfig.bFullMutex = 1;
       break;
     }
+    case SQLITE_CONFIG_MUTEX: {
+      /* Specify an alternative mutex implementation */
+      sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
+      break;
+    }
+    case SQLITE_CONFIG_GETMUTEX: {
+      /* Retrieve the current mutex implementation */
+      *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
+      break;
+    }
+#endif
+
+
     case SQLITE_CONFIG_MALLOC: {
       /* Specify an alternative malloc implementation */
       sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
@@ -275,16 +293,6 @@
       *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
       break;
     }
-    case SQLITE_CONFIG_MUTEX: {
-      /* Specify an alternative mutex implementation */
-      sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
-      break;
-    }
-    case SQLITE_CONFIG_GETMUTEX: {
-      /* Retrieve the current mutex implementation */
-      *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
-      break;
-    }
     case SQLITE_CONFIG_MEMSTATUS: {
       /* Enable or disable the malloc status collection */
       sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
diff --git a/src/mutex.c b/src/mutex.c
index 79ff86e..03cae57 100644
--- a/src/mutex.c
+++ b/src/mutex.c
@@ -11,19 +11,14 @@
 *************************************************************************
 ** This file contains the C functions that implement mutexes.
 **
-** The implementation in this file does not provide any mutual
-** exclusion and is thus suitable for use only in applications
-** that use SQLite in a single thread.  But this implementation
-** does do a lot of error checking on mutexes to make sure they
-** are called correctly and at appropriate times.  Hence, this
-** implementation is suitable for testing.
-** debugging purposes
+** This file contains code that is common across all mutex implementations.
+
 **
-** $Id: mutex.c,v 1.28 2008/09/01 18:34:20 danielk1977 Exp $
+** $Id: mutex.c,v 1.29 2008/10/07 15:25:48 drh Exp $
 */
 #include "sqliteInt.h"
 
-#ifndef SQLITE_MUTEX_NOOP
+#ifndef SQLITE_MUTEX_OMIT
 /*
 ** Initialize the mutex system.
 */
@@ -149,125 +144,4 @@
 }
 #endif
 
-#endif
-
-#ifdef SQLITE_MUTEX_NOOP_DEBUG
-/*
-** In this implementation, mutexes do not provide any mutual exclusion.
-** But the error checking is provided.  This implementation is useful
-** for test purposes.
-*/
-
-/*
-** The mutex object
-*/
-struct sqlite3_mutex {
-  int id;     /* The mutex type */
-  int cnt;    /* Number of entries without a matching leave */
-};
-
-/*
-** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
-** intended for use inside assert() statements.
-*/
-static int noopMutexHeld(sqlite3_mutex *p){
-  return p==0 || p->cnt>0;
-}
-static int noopMutexNotheld(sqlite3_mutex *p){
-  return p==0 || p->cnt==0;
-}
-
-/*
-** Initialize and deinitialize the mutex subsystem.
-*/
-static int noopMutexInit(void){ return SQLITE_OK; }
-static int noopMutexEnd(void){ return SQLITE_OK; }
-
-/*
-** The sqlite3_mutex_alloc() routine allocates a new
-** mutex and returns a pointer to it.  If it returns NULL
-** that means that a mutex could not be allocated. 
-*/
-static sqlite3_mutex *noopMutexAlloc(int id){
-  static sqlite3_mutex aStatic[6];
-  sqlite3_mutex *pNew = 0;
-  switch( id ){
-    case SQLITE_MUTEX_FAST:
-    case SQLITE_MUTEX_RECURSIVE: {
-      pNew = sqlite3Malloc(sizeof(*pNew));
-      if( pNew ){
-        pNew->id = id;
-        pNew->cnt = 0;
-      }
-      break;
-    }
-    default: {
-      assert( id-2 >= 0 );
-      assert( id-2 < sizeof(aStatic)/sizeof(aStatic[0]) );
-      pNew = &aStatic[id-2];
-      pNew->id = id;
-      break;
-    }
-  }
-  return pNew;
-}
-
-/*
-** This routine deallocates a previously allocated mutex.
-*/
-static void noopMutexFree(sqlite3_mutex *p){
-  assert( p->cnt==0 );
-  assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
-  sqlite3_free(p);
-}
-
-/*
-** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
-** to enter a mutex.  If another thread is already within the mutex,
-** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
-** SQLITE_BUSY.  The sqlite3_mutex_try() interface returns SQLITE_OK
-** upon successful entry.  Mutexes created using SQLITE_MUTEX_RECURSIVE can
-** be entered multiple times by the same thread.  In such cases the,
-** mutex must be exited an equal number of times before another thread
-** can enter.  If the same thread tries to enter any other kind of mutex
-** more than once, the behavior is undefined.
-*/
-static void noopMutexEnter(sqlite3_mutex *p){
-  assert( p->id==SQLITE_MUTEX_RECURSIVE || noopMutexNotheld(p) );
-  p->cnt++;
-}
-static int noopMutexTry(sqlite3_mutex *p){
-  assert( p->id==SQLITE_MUTEX_RECURSIVE || noopMutexNotheld(p) );
-  p->cnt++;
-  return SQLITE_OK;
-}
-
-/*
-** The sqlite3_mutex_leave() routine exits a mutex that was
-** previously entered by the same thread.  The behavior
-** is undefined if the mutex is not currently entered or
-** is not currently allocated.  SQLite will never do either.
-*/
-static void noopMutexLeave(sqlite3_mutex *p){
-  assert( noopMutexHeld(p) );
-  p->cnt--;
-  assert( p->id==SQLITE_MUTEX_RECURSIVE || noopMutexNotheld(p) );
-}
-
-sqlite3_mutex_methods *sqlite3DefaultMutex(void){
-  static sqlite3_mutex_methods sMutex = {
-    noopMutexInit,
-    noopMutexEnd,
-    noopMutexAlloc,
-    noopMutexFree,
-    noopMutexEnter,
-    noopMutexTry,
-    noopMutexLeave,
-
-    noopMutexHeld,
-    noopMutexNotheld
-  };
-
-  return &sMutex;
-}
-#endif /* SQLITE_MUTEX_NOOP_DEBUG */
+#endif /* SQLITE_OMIT_MUTEX */
diff --git a/src/mutex.h b/src/mutex.h
index 5f51dda..9457cb4 100644
--- a/src/mutex.h
+++ b/src/mutex.h
@@ -19,28 +19,21 @@
 ** Source files should #include the sqliteInt.h file and let that file
 ** include this one indirectly.
 **
-** $Id: mutex.h,v 1.8 2008/06/26 10:41:19 danielk1977 Exp $
+** $Id: mutex.h,v 1.9 2008/10/07 15:25:48 drh Exp $
 */
 
 
-#ifdef SQLITE_MUTEX_APPDEF
-/*
-** If SQLITE_MUTEX_APPDEF is defined, then this whole module is
-** omitted and equivalent functionality must be provided by the
-** application that links against the SQLite library.
-*/
-#else
 /*
 ** Figure out what version of the code to use.  The choices are
 **
-**   SQLITE_MUTEX_NOOP         For single-threaded applications that
-**                             do not desire error checking.
+**   SQLITE_MUTEX_OMIT         No mutex logic.  Not even stubs.  The
+**                             mutexes implemention cannot be overridden
+**                             at start-time.
 **
-**   SQLITE_MUTEX_NOOP_DEBUG   For single-threaded applications with
-**                             error checking to help verify that mutexes
-**                             are being used correctly even though they
-**                             are not needed.  Used when SQLITE_DEBUG is
-**                             defined on single-threaded builds.
+**   SQLITE_MUTEX_NOOP         For single-threaded applications.  No
+**                             mutual exclusion is provided.  But this
+**                             implementation can be overridden at
+**                             start-time.
 **
 **   SQLITE_MUTEX_PTHREADS     For multi-threaded applications on Unix.
 **
@@ -48,25 +41,22 @@
 **
 **   SQLITE_MUTEX_OS2          For multi-threaded applications on OS/2.
 */
-#define SQLITE_MUTEX_NOOP 1   /* The default */
-#if defined(SQLITE_DEBUG) && !SQLITE_THREADSAFE
-# undef SQLITE_MUTEX_NOOP
-# define SQLITE_MUTEX_NOOP_DEBUG
+#if !SQLITE_THREADSAFE
+# define SQLITE_MUTEX_OMIT
 #endif
-#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && SQLITE_OS_UNIX
-# undef SQLITE_MUTEX_NOOP
-# define SQLITE_MUTEX_PTHREADS
-#endif
-#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && SQLITE_OS_WIN
-# undef SQLITE_MUTEX_NOOP
-# define SQLITE_MUTEX_W32
-#endif
-#if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && SQLITE_OS_OS2
-# undef SQLITE_MUTEX_NOOP
-# define SQLITE_MUTEX_OS2
+#if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
+#  if SQLITE_OS_UNIX
+#    define SQLITE_MUTEX_PTHREADS
+#  elif SQLITE_OS_WIN
+#    define SQLITE_MUTEX_W32
+#  elif SQLITE_OS_OS2
+#    define SQLITE_MUTEX_OS2
+#  else
+#    define SQLITE_MUTEX_NOOP
+#  endif
 #endif
 
-#ifdef SQLITE_MUTEX_NOOP
+#ifdef SQLITE_MUTEX_OMIT
 /*
 ** If this is a no-op implementation, implement everything as macros.
 */
@@ -80,6 +70,4 @@
 #define sqlite3MutexAlloc(X)      ((sqlite3_mutex*)8)
 #define sqlite3MutexInit()        SQLITE_OK
 #define sqlite3MutexEnd()
-#endif
-
-#endif /* SQLITE_MUTEX_APPDEF */
+#endif /* defined(SQLITE_OMIT_MUTEX) */
diff --git a/src/mutex_noop.c b/src/mutex_noop.c
new file mode 100644
index 0000000..5900c4d
--- /dev/null
+++ b/src/mutex_noop.c
@@ -0,0 +1,186 @@
+/*
+** 2008 October 07
+**
+** The author disclaims copyright to this source code.  In place of
+** a legal notice, here is a blessing:
+**
+**    May you do good and not evil.
+**    May you find forgiveness for yourself and forgive others.
+**    May you share freely, never taking more than you give.
+**
+*************************************************************************
+** This file contains the C functions that implement mutexes.
+**
+** This implementation in this file does not provide any mutual
+** exclusion and is thus suitable for use only in applications
+** that use SQLite in a single thread.  The routines defined
+** here are place-holders.  Applications can substitute working
+** mutex routines at start-time using the
+**
+**     sqlite3_config(SQLITE_CONFIG_MUTEX,...)
+**
+** interface.
+**
+** If compiled with SQLITE_DEBUG, then additional logic is inserted
+** that does error checking on mutexes to make sure they are being
+** called correctly.
+**
+** $Id: mutex_noop.c,v 1.1 2008/10/07 15:25:48 drh Exp $
+*/
+#include "sqliteInt.h"
+
+
+#if defined(SQLITE_MUTEX_NOOP) && !defined(SQLITE_DEBUG)
+/*
+** Stub routines for all mutex methods.
+**
+** This routines provide no mutual exclusion or error checking.
+*/
+static int noopMutexHeld(sqlite3_mutex *p){ return 1; }
+static int noopMutexNotheld(sqlite3_mutex *p){ return 1; }
+static int noopMutexInit(void){ return SQLITE_OK; }
+static int noopMutexEnd(void){ return SQLITE_OK; }
+static sqlite3_mutex *noopMutexAlloc(int id){ return (sqlite3_mutex*)8; }
+static void noopMutexFree(sqlite3_mutex *p){ return; }
+static void noopMutexEnter(sqlite3_mutex *p){ return; }
+static int noopMutexTry(sqlite3_mutex *p){ return SQLITE_OK; }
+static void debugMutexLeave(sqlite3_mutex *p){ return; }
+
+sqlite3_mutex_methods *sqlite3DefaultMutex(void){
+  static sqlite3_mutex_methods sMutex = {
+    noopMutexInit,
+    noopMutexEnd,
+    noopMutexAlloc,
+    noopMutexFree,
+    noopMutexEnter,
+    noopMutexTry,
+    noopMutexLeave,
+
+    noopMutexHeld,
+    noopMutexNotheld
+  };
+
+  return &sMutex;
+}
+#endif /* defined(SQLITE_MUTEX_NOOP) && !defined(SQLITE_DEBUG) */
+
+#if defined(SQLITE_MUTEX_NOOP) && defined(SQLITE_DEBUG)
+/*
+** In this implementation, error checking is provided for testing
+** and debugging purposes.  The mutexes still do not provide any
+** mutual exclusion.
+*/
+
+/*
+** The mutex object
+*/
+struct sqlite3_mutex {
+  int id;     /* The mutex type */
+  int cnt;    /* Number of entries without a matching leave */
+};
+
+/*
+** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
+** intended for use inside assert() statements.
+*/
+static int debugMutexHeld(sqlite3_mutex *p){
+  return p==0 || p->cnt>0;
+}
+static int debugMutexNotheld(sqlite3_mutex *p){
+  return p==0 || p->cnt==0;
+}
+
+/*
+** Initialize and deinitialize the mutex subsystem.
+*/
+static int debugMutexInit(void){ return SQLITE_OK; }
+static int debugMutexEnd(void){ return SQLITE_OK; }
+
+/*
+** The sqlite3_mutex_alloc() routine allocates a new
+** mutex and returns a pointer to it.  If it returns NULL
+** that means that a mutex could not be allocated. 
+*/
+static sqlite3_mutex *debugMutexAlloc(int id){
+  static sqlite3_mutex aStatic[6];
+  sqlite3_mutex *pNew = 0;
+  switch( id ){
+    case SQLITE_MUTEX_FAST:
+    case SQLITE_MUTEX_RECURSIVE: {
+      pNew = sqlite3Malloc(sizeof(*pNew));
+      if( pNew ){
+        pNew->id = id;
+        pNew->cnt = 0;
+      }
+      break;
+    }
+    default: {
+      assert( id-2 >= 0 );
+      assert( id-2 < sizeof(aStatic)/sizeof(aStatic[0]) );
+      pNew = &aStatic[id-2];
+      pNew->id = id;
+      break;
+    }
+  }
+  return pNew;
+}
+
+/*
+** This routine deallocates a previously allocated mutex.
+*/
+static void debugMutexFree(sqlite3_mutex *p){
+  assert( p->cnt==0 );
+  assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
+  sqlite3_free(p);
+}
+
+/*
+** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
+** to enter a mutex.  If another thread is already within the mutex,
+** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
+** SQLITE_BUSY.  The sqlite3_mutex_try() interface returns SQLITE_OK
+** upon successful entry.  Mutexes created using SQLITE_MUTEX_RECURSIVE can
+** be entered multiple times by the same thread.  In such cases the,
+** mutex must be exited an equal number of times before another thread
+** can enter.  If the same thread tries to enter any other kind of mutex
+** more than once, the behavior is undefined.
+*/
+static void debugMutexEnter(sqlite3_mutex *p){
+  assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p) );
+  p->cnt++;
+}
+static int debugMutexTry(sqlite3_mutex *p){
+  assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p) );
+  p->cnt++;
+  return SQLITE_OK;
+}
+
+/*
+** The sqlite3_mutex_leave() routine exits a mutex that was
+** previously entered by the same thread.  The behavior
+** is undefined if the mutex is not currently entered or
+** is not currently allocated.  SQLite will never do either.
+*/
+static void debugMutexLeave(sqlite3_mutex *p){
+  assert( debugMutexHeld(p) );
+  p->cnt--;
+  assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p) );
+}
+
+sqlite3_mutex_methods *sqlite3DefaultMutex(void){
+  static sqlite3_mutex_methods sMutex = {
+    debugMutexInit,
+    debugMutexEnd,
+    debugMutexAlloc,
+    debugMutexFree,
+    debugMutexEnter,
+    debugMutexTry,
+    debugMutexLeave,
+
+    debugMutexHeld,
+    debugMutexNotheld
+  };
+
+  return &sMutex;
+}
+#endif /* defined(SQLITE_MUTEX_NOOP) && defined(SQLITE_DEBUG) */
diff --git a/src/os.c b/src/os.c
index 676a25f..006f620 100644
--- a/src/os.c
+++ b/src/os.c
@@ -13,7 +13,7 @@
 ** This file contains OS interface code that is common to all
 ** architectures.
 **
-** $Id: os.c,v 1.123 2008/09/23 16:41:30 danielk1977 Exp $
+** $Id: os.c,v 1.124 2008/10/07 15:25:48 drh Exp $
 */
 #define _SQLITE_OS_C_ 1
 #include "sqliteInt.h"
@@ -199,14 +199,14 @@
 */
 sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
   sqlite3_vfs *pVfs = 0;
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
   sqlite3_mutex *mutex;
 #endif
 #ifndef SQLITE_OMIT_AUTOINIT
   int rc = sqlite3_initialize();
   if( rc ) return 0;
 #endif
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
   mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
   sqlite3_mutex_enter(mutex);
@@ -268,7 +268,7 @@
 ** Unregister a VFS so that it is no longer accessible.
 */
 int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
   sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
   sqlite3_mutex_enter(mutex);
diff --git a/src/random.c b/src/random.c
index c3e425e..7fe42a5 100644
--- a/src/random.c
+++ b/src/random.c
@@ -15,7 +15,7 @@
 ** Random numbers are used by some of the database backends in order
 ** to generate random integer keys for tables or random filenames.
 **
-** $Id: random.c,v 1.26 2008/09/02 00:52:52 drh Exp $
+** $Id: random.c,v 1.27 2008/10/07 15:25:48 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -106,7 +106,7 @@
 */
 void sqlite3_randomness(int N, void *pBuf){
   unsigned char *zBuf = pBuf;
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
   sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
 #endif
   sqlite3_mutex_enter(mutex);
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 8141f8e..f749444 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.776 2008/10/07 05:27:11 shane Exp $
+** @(#) $Id: sqliteInt.h,v 1.777 2008/10/07 15:25:49 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -2056,7 +2056,7 @@
 void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
 int sqlite3MemoryAlarm(void (*)(void*, sqlite3_int64, int), void*, sqlite3_int64);
 
-#ifndef SQLITE_MUTEX_NOOP
+#ifndef SQLITE_MUTEX_OMIT
   sqlite3_mutex_methods *sqlite3DefaultMutex(void);
   sqlite3_mutex *sqlite3MutexAlloc(int);
   int sqlite3MutexInit(void);
diff --git a/src/test_config.c b/src/test_config.c
index aa4487d..4fa74af 100644
--- a/src/test_config.c
+++ b/src/test_config.c
@@ -16,7 +16,7 @@
 ** The focus of this file is providing the TCL testing layer
 ** access to compile-time constants.
 **
-** $Id: test_config.c,v 1.37 2008/09/23 10:16:05 drh Exp $
+** $Id: test_config.c,v 1.38 2008/10/07 15:25:49 drh Exp $
 */
 
 #include "sqliteLimit.h"
@@ -87,6 +87,12 @@
   Tcl_SetVar2(interp, "sqlite_options", "mem5", "0", TCL_GLOBAL_ONLY);
 #endif
 
+#ifdef SQLITE_MUTEX_OMIT
+  Tcl_SetVar2(interp, "sqlite_options", "mutex", "0", TCL_GLOBAL_ONLY);
+#else
+  Tcl_SetVar2(interp, "sqlite_options", "mutex", "1", TCL_GLOBAL_ONLY);
+#endif
+
 #ifdef SQLITE_OMIT_ALTERTABLE
   Tcl_SetVar2(interp, "sqlite_options", "altertable", "0", TCL_GLOBAL_ONLY);
 #else
diff --git a/src/test_wsd.c b/src/test_wsd.c
index 78889b8..a7fad26 100644
--- a/src/test_wsd.c
+++ b/src/test_wsd.c
@@ -14,7 +14,7 @@
 ** sqlite3_wsd_init() and sqlite3_wsd_find() functions required if the
 ** SQLITE_OMIT_WSD symbol is defined at build time.
 **
-** $Id: test_wsd.c,v 1.2 2008/09/02 16:22:29 danielk1977 Exp $
+** $Id: test_wsd.c,v 1.3 2008/10/07 15:25:49 drh Exp $
 */
 
 #if defined(SQLITE_OMIT_WSD) && defined(SQLITE_TEST)
@@ -84,4 +84,3 @@
 }
 
 #endif
-
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 46ccf51..5ec1a34 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -13,7 +13,7 @@
 ** This file contains code use to implement APIs that are part of the
 ** VDBE.
 **
-** $Id: vdbeapi.c,v 1.143 2008/10/07 14:06:11 danielk1977 Exp $
+** $Id: vdbeapi.c,v 1.144 2008/10/07 15:25:49 drh Exp $
 */
 #include "sqliteInt.h"
 #include "vdbeInt.h"
@@ -202,7 +202,7 @@
     rc = SQLITE_OK;
   }else{
     Vdbe *v = (Vdbe*)pStmt;
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
     sqlite3_mutex *mutex = v->db->mutex;
 #endif
     sqlite3_mutex_enter(mutex);
@@ -244,7 +244,7 @@
   int i;
   int rc = SQLITE_OK;
   Vdbe *p = (Vdbe*)pStmt;
-#ifndef SQLITE_MUTEX_NOOP
+#if SQLITE_THREADSAFE
   sqlite3_mutex *mutex = ((Vdbe*)pStmt)->db->mutex;
 #endif
   sqlite3_mutex_enter(mutex);
diff --git a/test/mutex1.test b/test/mutex1.test
index a1db9f2..ab5a248 100644
--- a/test/mutex1.test
+++ b/test/mutex1.test
@@ -9,11 +9,15 @@
 #
 #***********************************************************************
 #
-# $Id: mutex1.test,v 1.14 2008/09/03 01:08:02 drh Exp $
+# $Id: mutex1.test,v 1.15 2008/10/07 15:25:49 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 
+ifcapable !mutex {
+  finish_test
+  return
+}
 if {[info exists tester_do_binarylog]} {
   finish_test
   return
diff --git a/test/mutex2.test b/test/mutex2.test
index 6aa6715..9dfb03e 100644
--- a/test/mutex2.test
+++ b/test/mutex2.test
@@ -11,10 +11,14 @@
 #
 # Test scripts for deliberate failures of mutex routines.
 #
-# $Id: mutex2.test,v 1.8 2008/07/19 13:43:24 danielk1977 Exp $
+# $Id: mutex2.test,v 1.9 2008/10/07 15:25:49 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
+ifcapable !mutex {
+  finish_test
+  return
+}
 
 # deinitialize
 #
diff --git a/test/thread001.test b/test/thread001.test
index 8a2cbb5..7be3dbb 100644
--- a/test/thread001.test
+++ b/test/thread001.test
@@ -9,11 +9,14 @@
 #
 #***********************************************************************
 #
-# $Id: thread001.test,v 1.5 2008/07/12 14:52:20 drh Exp $
+# $Id: thread001.test,v 1.6 2008/10/07 15:25:49 drh Exp $
 
 set testdir [file dirname $argv0]
 
 source $testdir/tester.tcl
+ifcapable !mutex {
+  return
+}
 source $testdir/thread_common.tcl
 if {[info commands sqlthread] eq ""} {
   return
diff --git a/test/thread002.test b/test/thread002.test
index c31e3c4..5873ca5 100644
--- a/test/thread002.test
+++ b/test/thread002.test
@@ -12,7 +12,7 @@
 #   This test attempts to deadlock SQLite in shared-cache mode.
 #     
 #
-# $Id: thread002.test,v 1.3 2008/07/12 14:52:20 drh Exp $
+# $Id: thread002.test,v 1.4 2008/10/07 15:25:49 drh Exp $
 
 set testdir [file dirname $argv0]
 
@@ -22,7 +22,7 @@
   finish_test
   return
 }
-ifcapable !attach { 
+ifcapable !attach||!mutex { 
   finish_test
   return
 }
diff --git a/test/thread003.test b/test/thread003.test
index 05fe4d9..0db27c1 100644
--- a/test/thread003.test
+++ b/test/thread003.test
@@ -12,7 +12,7 @@
 #   This file contains tests that attempt to break the pcache module
 #   by bombarding it with simultaneous requests from multiple threads.
 #     
-# $Id: thread003.test,v 1.4 2008/08/30 09:10:17 danielk1977 Exp $
+# $Id: thread003.test,v 1.5 2008/10/07 15:25:49 drh Exp $
 
 set testdir [file dirname $argv0]
 
@@ -22,6 +22,10 @@
   finish_test
   return
 }
+ifcapable !mutex {
+  finish_test
+  return
+}
 
 # Set up a couple of different databases full of pseudo-randomly 
 # generated data.
@@ -190,5 +194,3 @@
 } {0}
 
 finish_test
-
-
diff --git a/test/thread1.test b/test/thread1.test
index c50d245..70bcc22 100644
--- a/test/thread1.test
+++ b/test/thread1.test
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script is multithreading behavior
 #
-# $Id: thread1.test,v 1.7 2004/06/19 00:16:31 drh Exp $
+# $Id: thread1.test,v 1.8 2008/10/07 15:25:49 drh Exp $
 
 
 set testdir [file dirname $argv0]
@@ -19,6 +19,10 @@
 
 # Skip this whole file if the thread testing code is not enabled
 #
+ifcapable !mutex {
+  finish_test
+  return
+}
 if {[llength [info command thread_step]]==0 || [sqlite3 -has-codec]} {
   finish_test
   return
diff --git a/test/thread2.test b/test/thread2.test
index 1d9a208..9547acc 100644
--- a/test/thread2.test
+++ b/test/thread2.test
@@ -11,16 +11,13 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script is multithreading behavior
 #
-# $Id: thread2.test,v 1.2 2006/01/18 18:33:42 danielk1977 Exp $
+# $Id: thread2.test,v 1.3 2008/10/07 15:25:49 drh Exp $
 
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 
-# This file swaps database connections between threads. This
-# is illegal if memory-management is enabled, so skip this file
-# in that case.
-ifcapable memorymanage {
+ifcapable !mutex {
   finish_test
   return
 }
diff --git a/tool/mksqlite3c.tcl b/tool/mksqlite3c.tcl
index b8efe2b..bf8ce16 100644
--- a/tool/mksqlite3c.tcl
+++ b/tool/mksqlite3c.tcl
@@ -217,6 +217,7 @@
    mem5.c
    mem6.c
    mutex.c
+   mutex_noop.c
    mutex_os2.c
    mutex_unix.c
    mutex_w32.c