[corlib] Ensure Thread.ManagedThreadId is unique per thread.
[mono.git] / mcs / class / corlib / System.Threading / ReaderWriterLock.cs
index 7cb1213cd5d9583c53fba1dcdaf75c50b8a90e2f..ebb718cce02f0cc338a6dc47051d2ee874f8688b 100644 (file)
@@ -173,11 +173,15 @@ namespace System.Threading
                        lock (this) {
                                if (!HasWriterLock())
                                        throw new ApplicationException ("The thread does not have the writer lock.");
-                               
-                               state = lockCookie.ReaderLocks;
-                               reader_locks [Thread.CurrentThreadId] = state;
-                               if (readers > 0) {
-                                       Monitor.PulseAll (this);
+
+                               if (lockCookie.WriterLocks != 0)
+                                       state++;
+                               else {
+                                       state = lockCookie.ReaderLocks;
+                                       reader_locks [Thread.CurrentThreadId] = state;
+                                       if (readers > 0) {
+                                               Monitor.PulseAll (this);
+                                       }
                                }
                                
                                // MSDN: A thread does not block when downgrading from the writer lock,