fix for: https://issues.apache.org/jira/browse/AMQCPP-437

git-svn-id: https://svn.apache.org/repos/asf/activemq/activemq-cpp/branches/activemq-cpp-3.4.x@1402626 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp b/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp
index 4358657..2d7c458 100644
--- a/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp
+++ b/activemq-cpp/src/main/activemq/core/ActiveMQSessionExecutor.cpp
@@ -81,7 +81,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 void ActiveMQSessionExecutor::wakeup() {
 
-    Pointer<TaskRunner> taskRunner = this->taskRunner;
+    Pointer<TaskRunner> taskRunner;
     synchronized( messageQueue.get() ) {
         if( this->taskRunner == NULL ) {
             this->taskRunner.reset( new DedicatedTaskRunner( this ) );
@@ -110,9 +110,17 @@
 
     if( messageQueue->isRunning() ) {
         messageQueue->stop();
-        Pointer<TaskRunner> taskRunner = this->taskRunner;
+
+        Pointer<TaskRunner> taskRunner;
+        synchronized( messageQueue.get() ) {
+        	taskRunner = this->taskRunner;
+
+            if( taskRunner != NULL ) {
+                this->taskRunner.reset( NULL );
+            }
+        }
+
         if( taskRunner != NULL ) {
-            this->taskRunner.reset( NULL );
             taskRunner->shutdown();
         }
     }