Index: source/ariba/utility/system/StartupWrapper.cpp
===================================================================
--- source/ariba/utility/system/StartupWrapper.cpp	(revision 4462)
+++ source/ariba/utility/system/StartupWrapper.cpp	(revision 4483)
@@ -48,5 +48,4 @@
 
 SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
-SystemEventType StartupWrapperEventShutdown("StartupWrapperEventShutdown");
 
 StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){
@@ -73,9 +72,5 @@
 #endif
 
-void StartupWrapper::initSystem(){
-
-	static bool initialized = false;
-	if( initialized ) return;
-	initialized = true;
+void StartupWrapper::startSystem(){
 
 	//
@@ -121,4 +116,8 @@
 }
 
+void StartupWrapper::stopSystem(){
+	SystemQueue::instance().cancel();
+}
+
 void StartupWrapper::initConfig(string filename){
 	configurations.push( filename );
@@ -142,9 +141,4 @@
 
 		service->startup();
-
-	} else if( event.getType() == StartupWrapperEventShutdown ){
-
-		service->shutdown();
-		SystemQueue::instance().cancel();
 
 	}
@@ -174,12 +168,24 @@
 
 	if(block){
-		SystemEvent ev (service->wrapper, StartupWrapperEventShutdown);
-		service->wrapper->handleSystemEvent(ev);
-
+		// call directly
+		service->shutdown();
 	}else{
-		SystemQueue::instance().scheduleEvent(
-				SystemEvent( service->wrapper, StartupWrapperEventShutdown, NULL), 0 );
+		// call async, but not using systemqueue! // TODO: mem leak
+		AsyncShutdown* async = new AsyncShutdown(service);
+		async->runBlockingMethod();
 	}
 }
 
+StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
+	: service(_service){
+}
+
+void StartupWrapper::AsyncShutdown::blockingFunction(){
+	service->shutdown();
+}
+
+void StartupWrapper::AsyncShutdown::dispatchFunction(){
+	//unused
+}
+
 }} // namespace ariba, utility
Index: source/ariba/utility/system/StartupWrapper.h
===================================================================
--- source/ariba/utility/system/StartupWrapper.h	(revision 4462)
+++ source/ariba/utility/system/StartupWrapper.h	(revision 4483)
@@ -44,5 +44,6 @@
 #include "SystemQueue.h"
 #include "StartupInterface.h"
-#include "../configuration/Configuration.h"
+#include "ariba/utility/configuration/Configuration.h"
+#include "BlockingMethod.h"
 
 #ifdef UNDERLAY_OMNET
@@ -69,5 +70,7 @@
 class StartupWrapper : public SystemEventListener {
 public:
-	static void initSystem();
+	static void startSystem();
+	static void stopSystem();
+
 	static void initConfig(string filename);
 	static void startup(StartupInterface* service, bool block = true);
@@ -96,4 +99,15 @@
 	void waitForExit();
 	StartupInterface* service;
+
+	class AsyncShutdown : public BlockingMethod {
+	public:
+		AsyncShutdown(StartupInterface* _service);
+	protected:
+		virtual void dispatchFunction();
+		virtual void blockingFunction(); // unused
+	private:
+		StartupInterface* service;
+	};
+
 };
 
Index: source/ariba/utility/system/SystemQueue.cpp
===================================================================
--- source/ariba/utility/system/SystemQueue.cpp	(revision 4462)
+++ source/ariba/utility/system/SystemQueue.cpp	(revision 4483)
@@ -130,6 +130,14 @@
 
 	// cause the thread to exit
-	running = false;
-	itemsAvailable.notify_all();
+	{
+		boost::mutex::scoped_lock lock(queueMutex);
+		running = false;
+
+		while( eventsQueue.size() > 0 ){
+			eventsQueue.erase( eventsQueue.begin() );
+		}
+
+		itemsAvailable.notify_all();
+	}
 
 	// wait that the thread has exited
@@ -139,8 +147,4 @@
 	delete queueThread;
 	queueThread = NULL;
-
-	while( eventsQueue.size() > 0 ){
-		eventsQueue.erase( eventsQueue.begin() );
-	}
 }
 
@@ -151,15 +155,19 @@
 
 void SystemQueue::QueueThread::insert( const SystemEvent& event, uint32_t delay ){
-	{
-		boost::mutex::scoped_lock lock( queueMutex );
-
-		eventsQueue.push_back( event );
-		eventsQueue.back().scheduledTime = boost::posix_time::microsec_clock::local_time();
-		eventsQueue.back().delayTime = delay;
-		eventsQueue.back().remainingDelay = delay;
-
-		onItemInserted( event );
-		itemsAvailable.notify_all();
-	}
+
+	// if this is called from a module that is currently handling
+	// a thread (called from SystemQueue::onNextQueueItem), the
+	// thread is the same anyway and the mutex will be already
+	// aquired, otherwise we aquire it now
+
+	boost::mutex::scoped_lock lock( queueMutex );
+
+	eventsQueue.push_back( event );
+	eventsQueue.back().scheduledTime = boost::posix_time::microsec_clock::local_time();
+	eventsQueue.back().delayTime = delay;
+	eventsQueue.back().remainingDelay = delay;
+
+	onItemInserted( event );
+	itemsAvailable.notify_all();
 }
 
@@ -177,7 +185,7 @@
 		while ( obj->eventsQueue.empty() && obj->running ){
 
-			const boost::system_time duration =
-					boost::get_system_time() +
-					boost::posix_time::milliseconds(40);
+//			const boost::system_time duration =
+//					boost::get_system_time() +
+//					boost::posix_time::milliseconds(100);
 
 			obj->itemsAvailable.wait( lock );
@@ -185,23 +193,23 @@
 		}
 
+		//
 		// work all the items that are currently in the queue
-
-		while( !obj->eventsQueue.empty() ) {
-
-			// fetch the first item in the queue and deliver it to the
-			// queue handler
+		//
+
+		while( !obj->eventsQueue.empty() && obj->running ) {
+
+			// fetch the first item in the queue
+			// and deliver it to the queue handler
 			SystemEvent ev = obj->eventsQueue.front();
 			obj->eventsQueue.erase( obj->eventsQueue.begin() );
 
-			{
-				// unlock the queue to that an event handler
-				// can insert new items into the queue
-//				obj->queueMutex.unlock();
-				obj->onNextQueueItem( ev );
-//				obj->queueMutex.lock();
-			}
+			// call the queue and this will
+			// call the actual event handler
+			obj->onNextQueueItem( ev );
 
 		} // !obj->eventsQueue.empty() )
 	} // while (obj->running)
+
+	logging_debug("system queue exited");
 }
 
