Index: trunk/psModules/src/imcombine/pmSubtraction.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtraction.c	(revision 19059)
+++ trunk/psModules/src/imcombine/pmSubtraction.c	(revision 19061)
@@ -215,23 +215,34 @@
                                   region.y0 - size, region.y1 + size); // Add a border
 
-    // Casting away const
-    psMutexLock((psImage*)image);
+    bool threaded = pmSubtractionThreaded(); // Are we running threaded?
+
+    // Casting away const for image, mask
+    if (threaded) {
+        psMutexLock((psImage*)image);
+    }
     psImage *subImage = psImageSubset((psImage*)image, border); // Subimage to convolve
-    psMutexUnlock((psImage*)image);
-
-    // Casting away const
-    psMutexLock((psImage*)mask);
+    if (threaded) {
+        psMutexUnlock((psImage*)image);
+        psMutexLock((psImage*)mask);
+    }
     psImage *subMask = mask ? psImageSubset((psImage*)mask, border) : NULL; // Subimage mask
-    psMutexUnlock((psImage*)mask);
+    if (threaded) {
+        psMutexUnlock((psImage*)mask);
+    }
 
     psImage *convolved = psImageConvolveFFT(NULL, subImage, subMask, maskVal, kernel); // Convolution
 
-    psMutexLock((psImage*)image);
+    if (threaded) {
+        psMutexLock((psImage*)image);
+    }
     psFree(subImage);
-    psMutexUnlock((psImage*)image);
-
-    psMutexLock((psImage*)mask);
+    if (threaded) {
+        psMutexUnlock((psImage*)image);
+        psMutexLock((psImage*)mask);
+    }
     psFree(subMask);
-    psMutexUnlock((psImage*)mask);
+    if (threaded) {
+        psMutexUnlock((psImage*)mask);
+    }
 
     // Now, we have to chop off the borders, and stick it in where it belongs
@@ -239,7 +250,11 @@
     psImage *subConv = psImageSubset(convolved, psRegionSet(size, -size, size, -size)); // Cut off the edges
 
-    psMutexLock(target);
+    if (threaded) {
+        psMutexLock(target);
+    }
     psImage *subTarget = psImageSubset(target, region); // Target for this subregion
-    psMutexUnlock(target);
+    if (threaded) {
+        psMutexUnlock(target);
+    }
     if (background != 0.0) {
         psBinaryOp(subTarget, subConv, "+", psScalarAlloc(background, PS_TYPE_F32));
@@ -252,7 +267,11 @@
     psFree(subConv);
     psFree(convolved);
-    psMutexLock(target);
+    if (threaded) {
+        psMutexLock(target);
+    }
     psFree(subTarget);
-    psMutexUnlock(target);
+    if (threaded) {
+        psMutexUnlock(target);
+    }
     return;
 }
