You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/10/26 23:21:14 UTC

svn commit: r830001 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs

Author: tabish
Date: Mon Oct 26 22:21:14 2009
New Revision: 830001

URL: http://svn.apache.org/viewvc?rev=830001&view=rev
Log:
Fix faulty shutdown logic.  

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs?rev=830001&r1=830000&r2=830001&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Threads/DedicatedTaskRunner.cs Mon Oct 26 22:21:14 2009
@@ -43,14 +43,10 @@
             this.task = task;
 
             this.theThread = new Thread(Run);
+            this.theThread.IsBackground = true;
             this.theThread.Start();
         }
 
-        ~DedicatedTaskRunner()
-        {
-            this.Shutdown();
-        }
-
         public void Shutdown(TimeSpan timeout)
         {
             lock(mutex) 
@@ -62,16 +58,16 @@
 
                 // Wait till the thread stops ( no need to wait if shutdown
                 // is called from thread that is shutting down)
-                if(!this.terminated) 
+                if(Thread.CurrentThread != this.theThread && !this.terminated) 
                 {
                     Monitor.Wait(this.mutex, timeout);
                 }
-            }            
+            }
         }
 
         public void Shutdown()
         {
-            this.Shutdown(new TimeSpan(Timeout.Infinite));
+            this.Shutdown(TimeSpan.FromMilliseconds(-1));
         }
 
         public void Wakeup()
@@ -101,6 +97,7 @@
                         
                         if(this.shutdown)
                         {
+                            
                             return;
                         }
                     }
@@ -126,13 +123,15 @@
             catch
             {
             }
-        
-            // Make sure we notify any waiting threads that thread
-            // has terminated.
-            lock(this.mutex)
-            {
-                this.terminated = true;
-                Monitor.PulseAll(this.mutex);
+            finally
+            {        
+                // Make sure we notify any waiting threads that thread
+                // has terminated.
+                lock(this.mutex)
+                {
+                    this.terminated = true;
+                    Monitor.PulseAll(this.mutex);
+                }
             }
         }
     }