Author: dick
Date: 2007-09-25 11:28:09 -0400 (Tue, 25 Sep 2007)
New Revision: 86337

Modified:
   trunk/mcs/class/corlib/System.Threading/ChangeLog
   trunk/mcs/class/corlib/System.Threading/Thread.cs
Log:

2007-09-25  Dick Porter  <[EMAIL PROTECTED]>

        * Thread.cs: Keep ManagedThreadId constant over the lifetime of a
        Thread.  Patch from [EMAIL PROTECTED] fixing bugs 325367 and
        325566.




Modified: trunk/mcs/class/corlib/System.Threading/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Threading/ChangeLog   2007-09-25 15:25:09 UTC 
(rev 86336)
+++ trunk/mcs/class/corlib/System.Threading/ChangeLog   2007-09-25 15:28:09 UTC 
(rev 86337)
@@ -1,3 +1,9 @@
+2007-09-25  Dick Porter  <[EMAIL PROTECTED]>
+
+       * Thread.cs: Keep ManagedThreadId constant over the lifetime of a
+       Thread.  Patch from [EMAIL PROTECTED] fixing bugs 325367 and
+       325566.
+
 2007-09-25  Jonathan Pobst  <[EMAIL PROTECTED]>
 
        * SynchronizationContext.cs: Implement SetSynchronizationContext.

Modified: trunk/mcs/class/corlib/System.Threading/Thread.cs
===================================================================
--- trunk/mcs/class/corlib/System.Threading/Thread.cs   2007-09-25 15:25:09 UTC 
(rev 86336)
+++ trunk/mcs/class/corlib/System.Threading/Thread.cs   2007-09-25 15:28:09 UTC 
(rev 86337)
@@ -116,6 +116,9 @@
                private MulticastDelegate threadstart;
                private string thread_name=null;
                
+               private static int _managed_id_counter;
+               private int managed_id;
+               
                private IPrincipal _principal;
 
                public static Context CurrentContext {
@@ -293,11 +296,16 @@
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern IntPtr Thread_internal (MulticastDelegate start);
 
+               private static int GetNewManagedId() {
+                       return Interlocked.Increment(ref _managed_id_counter);
+               }
+
                public Thread(ThreadStart start) {
                        if(start==null) {
                                throw new ArgumentNullException("Null 
ThreadStart");
                        }
                        threadstart=start;
+                       managed_id=GetNewManagedId();
                }
 
 #if NET_2_0
@@ -825,6 +833,7 @@
 
                        threadstart = start;
                        stack_size = maxStackSize;
+                       managed_id = GetNewManagedId();
                }
 
                public Thread (ParameterizedThreadStart start)
@@ -833,6 +842,7 @@
                                throw new ArgumentNullException ("start");
 
                        threadstart = start;
+                       managed_id = GetNewManagedId();
                }
 
                public Thread (ParameterizedThreadStart start, int maxStackSize)
@@ -844,6 +854,7 @@
 
                        threadstart = start;
                        stack_size = maxStackSize;
+                       managed_id = GetNewManagedId();
                }
 
                [MonoTODO ("limited to CompressedStack support")]
@@ -859,7 +870,7 @@
 
                public int ManagedThreadId {
                [ReliabilityContractAttribute (Consistency.WillNotCorruptState, 
Cer.Success)]
-                       get { return (int)thread_id; }
+                       get { return managed_id; }
                }
 
                [MonoTODO("Not implemented")]
@@ -917,8 +928,7 @@
                [ComVisible (false)]
                public override int GetHashCode ()
                {
-                       // ??? overridden but not guaranteed to be unique ???
-                       return (int)thread_id;
+                       return managed_id;
                }
 
                public void Start (object parameter)

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to