Index: trunk/FACT++/src/StateMachineImp.cc
===================================================================
--- trunk/FACT++/src/StateMachineImp.cc	(revision 14566)
+++ trunk/FACT++/src/StateMachineImp.cc	(revision 14567)
@@ -177,7 +177,6 @@
 void StateMachineImp::PushEvent(Event *cmd)
 {
-    fMutex.lock();
+    const lock_guard<mutex> guard(fMutex);
     fEventQueue.push(cmd);
-    fMutex.unlock();
 }
 
@@ -193,5 +192,5 @@
 Event *StateMachineImp::PopEvent()
 {
-    fMutex.lock();
+    const lock_guard<mutex> guard(fMutex);
 
     // Get the next event from the stack
@@ -199,6 +198,4 @@
     Event *cmd = fEventQueue.front();
     fEventQueue.pop();
-
-    fMutex.unlock();
 
     return cmd;
@@ -554,8 +551,6 @@
 #endif
 
-    fMutexEvt.lock();
+    const lock_guard<mutex> guard(fMutexEvt);
     fListOfEvents.push_back(evt);
-    fMutexEvt.unlock();
-
     return *evt;
 }
@@ -622,8 +617,6 @@
     EventImp *evt = CreateService(name);
 
-    fMutexEvt.lock();
+    const lock_guard<mutex> guard(fMutexEvt);
     fListOfEvents.push_back(evt);
-    fMutexEvt.unlock();
-
     return *evt;
 }
@@ -631,11 +624,13 @@
 void StateMachineImp::Unsubscribe(EventImp *evt)
 {
-    const lock_guard<mutex> guard(fMutexEvt);
-
-    auto it = find(fListOfEvents.begin(), fListOfEvents.end(), evt);
-    if (it==fListOfEvents.end())
+    {
+        const lock_guard<mutex> guard(fMutexEvt);
+
+        auto it = find(fListOfEvents.begin(), fListOfEvents.end(), evt);
+        if (it==fListOfEvents.end())
         return;
 
-    fListOfEvents.erase(it);
+        fListOfEvents.erase(it);
+    }
     delete evt;
 }
