Index: /source/ariba/utility/system/SystemQueue.cpp
===================================================================
--- /source/ariba/utility/system/SystemQueue.cpp	(revision 4706)
+++ /source/ariba/utility/system/SystemQueue.cpp	(revision 4712)
@@ -141,18 +141,23 @@
 	// cause the thread to exit
 	{
+		// get the lock, when we got the lock the 
+		// queue thread must be in itemsAvailable.wait()
 		boost::mutex::scoped_lock lock(queueMutex);
+		
+		// set the running indicator and signal to run on
+		// this will run the thread and quit it
 		running = false;
-
-		while( eventsQueue.size() > 0 ){
-			eventsQueue.erase( eventsQueue.begin() );
-		}
-
 		itemsAvailable.notify_all();
 	}
 
-	// wait that the thread has exited
-	// and delete it, so that a subsuquent run() can be called
-
+	// wait until the thread has exited
 	queueThread->join();
+
+	// delete pending events
+	while( eventsQueue.size() > 0 ){
+		eventsQueue.erase( eventsQueue.begin() );
+	}
+
+	// delete the thread, so that a subsuquent run() can be called
 	delete queueThread;
 	queueThread = NULL;
@@ -193,12 +198,12 @@
 		// this and cause the thread to exit
 
-		while ( obj->eventsQueue.empty() && obj->running ){
+		while ( obj->running && obj->eventsQueue.empty() ){
 
 //			const boost::system_time duration =
 //					boost::get_system_time() +
 //					boost::posix_time::milliseconds(100);
+//			obj->itemsAvailable.timed_wait( lock, duration );
 
 			obj->itemsAvailable.wait( lock );
-//			obj->itemsAvailable.timed_wait( lock, duration );
 		}
 
@@ -207,5 +212,5 @@
 		//
 
-		while( !obj->eventsQueue.empty() && obj->running ) {
+		while( obj->running && (!obj->eventsQueue.empty()) ) {
 
 			// fetch the first item in the queue
