This is a theoretical question; I don't have a real problem to solve, I just want to understand how this works.
I found out that if a thread does not allow you to exit ReaderWriterLock, then other threads will not be able to get a lock even after the end of the original thread. Is there a good reason why ReaderWriterLock does not provide a lock to waiting threads as soon as the thread to which the lock belongs ends?
Here is an example that demonstrates the problem.
static void Main(string[] args) { ReaderWriterLockSlim readerWriterLock = new ReaderWriterLockSlim(); Thread t1 = new Thread((a) => { readerWriterLock.EnterReadLock(); // this thread omits to Exit the lock.... }); Thread t2 = new Thread((a) => { readerWriterLock.EnterWriteLock(); }); t1.Start(); t2.Start(); // wait for all threads to finish t1.Join(); t2.Join(); }
: , , .
, . , , , , - - , , .
, , , , , .
, , , , . , , , , , . , , , , , . , , , , , - , , , .
Source: https://habr.com/ru/post/1732236/More articles:Ant: How can I subtract two properties (containing timestamps)? - javaApache Tomcat and Ruby - ruby ââ| fooobar.comPosition: Absolute Non-Own Parent in IE6 - htmlWhich one is best suited for enterprise-level JS programming - jQuery or Prototype, and why? - javascriptXmlWriterSettings do not affect XmlWriter created from XmlDocument - c #Implementing a search or creation while importing data with flat files - xmlPython based document metadata analyzer? - pythonLearn version control with git first or through SVN? - gitGoogle Maps, SQL, XML, Ajax oh my! - javascriptSAP hosted web service consumed by a .NET application - web-servicesAll Articles