diff --git a/qtools/qcstring.h b/qtools/qcstring.h
index abf30b3..31e7e08 100644
--- a/qtools/qcstring.h
+++ b/qtools/qcstring.h
@@ -357,6 +357,16 @@ public:
       char str[SHORT_STR_CAPACITY]; // size including 0-terminator
     };
 
+    static int atomic_inc(int *p)
+    {
+        return __sync_add_and_fetch(p, 1);
+    }
+
+    static int atomic_dec(int *p)
+    {
+        return __sync_add_and_fetch(p, -1);
+    }
+
     // ref counting string header
     struct LSHeader
     {
@@ -385,7 +395,7 @@ public:
       // remove out reference to the data. Frees memory if no more users
       void dispose()
       {
-        if (--refCount<0) free(this);
+        if (atomic_dec(&refCount)<0) free(this);
       }
 
       // resizes LSData so it can hold size bytes (which includes the 0 terminator!)
@@ -445,7 +455,7 @@ public:
             else
             {
               u.l.d = s.u.l.d;
-              u.l.d->refCount++;
+              atomic_inc(&u.l.d->refCount);
             }
           }
           else // self-assignment
@@ -536,7 +546,7 @@ public:
             else // copy by reference
             {
               u.l.d = s.u.l.d;
-              u.l.d->refCount++;
+              atomic_inc(&u.l.d->refCount);
             }
           }
           else // self-assignment
