Commit Graph
37 Commits
Author SHA1 Message Date
Marek Safar cbca01b433 Add dispose checks to ReaderWriterLockSlim and fix race in currentThreadState initialization 2013-08-19 10:22:23 +02:00
Jérémie Laval e223f978be [System.Core] Fix possible state corruption in ReaderWriterLockSlim. Fix #6635.
The problem was triggered in a situation where threads were competing for the write-lock and were using timeout:
   - thread t1 takes the lock (state = RwWrite)
   - thread t2 tries to take the lock but fails because of t1, it registers it interest (state = RwWrite | RwWait) and goes to sleep
   - thread t3 tries to take the lock but failes because of t1 and don't register any interest because t2 did it already (state = RwWrite | RwWait)
   - t1 releases the lock, waking up t2 and t3 which race for it with t3 winning the race (state = RwWrite)
   - t2 tries to go back to sleep but has overrun its timeout so it exits.
   - with t2 exiting, it tries to remove previously registered interest (state = RwWrite - RwWait -> corruption).
2012-09-04 18:53:18 +01:00
Marek Safar 8566a284a2 Update more 4.5 api 2012-06-08 11:44:55 +01:00
Jeremie Laval 51f51a430f Add RwWrite flag to status check when already owning upgradeable lock. Fix #802. 2011-11-04 01:15:29 +01:00
Jeremie Laval e2e28d46d4 Set success boolean in all cases and avoid state masking. Fix #124 2011-11-01 16:28:24 +01:00
Jérémie Laval 52ccbf2963 Protect entering ReaderWriterLockSlim upgradable mode against async exceptions. 2011-04-05 15:24:47 +02:00
Jérémie Laval ff80eb8f67 [ReaderWriterLockSlim] Fix for #656353. Add corresponding unit test.
When in SupportsRecursion mode, a test was not including proper state check for short-circuiting.
2010-12-01 14:38:28 +00:00
Jérémie Laval 4016c03e34 Fix ReaderWriterLockSlim Exit methods in SupportsRecursion mode and add corresponding unit tests 2010-11-23 10:59:07 +00:00
Jérémie Laval d687cbbd43 Another fix related to the rebase 2010-11-18 12:05:34 +00:00
Jérémie Laval d0623ba210 Fix compile error introduced by rebasing 2010-11-18 12:05:34 +00:00
Jérémie Laval 50d7302246 Protect ExitUpgradeable part of ReaderWriterLockSlim against asynchronous exception.
This ensure that the lock state remains consistent even when it's interrupted by an async exception (such as ThreadAbortException).
2010-11-18 12:05:32 +00:00
Jérémie Laval 01a09fd9fe Protect Enter/Exit write part of ReaderWriterLockSlim against asynchronous exception.
This ensure that the lock state remains consistent even when it's interrupted by an async exception (such as ThreadAbortException).
2010-11-18 12:05:31 +00:00
Jérémie Laval ec9b7a2216 Protect Enter/Exit read part of ReaderWriterLockSlim against asynchronous exception.
This ensure that the lock state remains consistent even when it's interrupted by an async exception (such as ThreadAbortException).
2010-11-18 12:05:31 +00:00
Jérémie Laval fe0be24bea Final performance improvement on ReaderWriterLockSlim 2010-11-10 13:38:55 +00:00
Jérémie Laval 87f072d29c Remove CurrentLockState in ReaderWriterLockSlim and reuse ThreadLockState instance more often. 2010-11-09 14:57:14 +00:00
Jérémie Laval 5f71cbd7d6 Small condition fix in ReaderWriterLockSlim, avoid an extra loop pass. 2010-11-09 14:57:14 +00:00
Jérémie Laval 63ebd7b9d6 ReaderWriterLockSlim performance improvements 2010-11-04 15:51:33 +00:00
Jérémie Laval 0932636327 Add tiny bit of doc on ReaderWriterLockSlim. 2010-11-03 20:14:06 +00:00
Jérémie Laval 8e3bbe1893 [ReaderWriterLockSlim] Fix state corruption and race in a special interleaving.
Fix possible state corruption in the case where Upgradeable wasn't reactivating its read bit after a downgrade and set events accordingly. Fix possible race where a write process wannabe could step in the middle of Upgradeable actually upgrading to write mode.
2010-09-29 14:52:20 +01:00
Jérémie Laval e0d372e7bf Turn Is*LockHeld properties into thread-specific values in ReaderWriterLockSlim. Add corresponding unit tests. 2010-09-28 13:23:05 +01:00
Jérémie Laval 4b844f8105 Add tidbits of documentation to ReaderWriterLockSlim. 2010-09-22 11:33:55 +01:00
Jérémie Laval 65180d590b Also set readerDoneEvent when exiting an upgradeable lock and reader condition is correct.
It could cause a deadlock when a writer tested the rwlock value before RwRead was removed and another Upgradeable operation happened at the same time.
2010-09-22 11:04:03 +01:00
Jérémie Laval 5c52755ffd Allow recursive Write + n * Read lock pattern for ReaderWriterLockSlim and add corresponding unit test 2010-09-01 14:26:42 +01:00
Jérémie Laval c70d5fff59 Generalize ThreadLockState to include recursive count informations and update them accordingly in the different Enter/Exit methods 2010-09-01 13:56:11 +01:00
Jérémie Laval ac4bd81b23 Change the key of the inner dictionary to an int id instead of the instance itself
It prevents object references to the rwlslim to be kept and thus not GC'ed
2010-09-01 11:10:09 +01:00
Jérémie Laval 3f65781d83 Split ReaderWriterLockSlim helper classes into their own files 2010-09-01 11:10:09 +01:00
Jérémie Laval cf6cb84548 Fix non 4.0 build of ReaderWriterLockSlim.
It needs to be cleaned up though.
2010-08-31 17:51:35 +01:00
Jérémie Laval f77f094d46 Enable basic recursion support in ReaderWriterLockSlim. Works when reacquiring lock of the same type. 2010-08-31 17:01:39 +01:00
Jérémie Laval a13cb7d229 Use ManualResetEventSlim instances to wait for lock changes instead of hardcoded Thread.Sleep calls in ReaderWriterLockSlim. 2010-08-31 17:01:39 +01:00
Jérémie Laval f706ec1dd4 Remove unused bit position constants in ReaderWriterLockSlim 2010-08-31 17:01:39 +01:00
Jérémie Laval dbf53c74c4 Finish reimplementation of ReaderWriterLockSlim so that it pass unit tests. 2010-08-31 17:01:36 +01:00
Jérémie Laval 8297cbde16 Refactor ThreadLockState acquisition into a real per-thread, per-rwlock-instance value 2010-08-31 17:01:35 +01:00
Jérémie Laval 16e2f091f0 Rework ReaderWriterLockSlim to use simpler Interlocked arithmetic. 2010-08-31 17:01:35 +01:00
Atsushi Eno 440ba3208d 2009-06-15 Atsushi Enomoto <[email protected]>
* ReaderWriterLockSlim.cs : fix deadlock when entered
          read lock -> entered writer lock -> exited writer lock
          -> exited read lock and then entered reader lock.
          Fixed bug #512485, patch by Kazuki Oikawa.

        * ReaderWriterLockSlimTest.cs : test for bug #512485, by
          Kazuki Oikawa.


svn path=/trunk/mcs/; revision=136109
2009-06-15 10:27:41 +00:00
Marek Safar 2101a3d1e7 2009-01-18 Marek Safar <[email protected]>
* ReaderWriterLockSlim.cs: Implemented all properties.


svn path=/trunk/mcs/; revision=123729
2009-01-18 13:24:26 +00:00
Marek Safar f1f810e35b 2008-12-02 Marek Safar <[email protected]>
* ReaderWriterLockSlim.cs: Initial merge.


svn path=/trunk/mcs/; revision=120496
2008-12-02 16:25:32 +00:00
Miguel de Icaza 6970bc3360 Add initial implementation of ReaderWriterLockSlim, it is missing support for recursive locks, and support for flagging errors
svn path=/trunk/mcs/; revision=120435
2008-12-02 00:55:07 +00:00