December 2019
Intermediate to advanced
346 pages
9h 8m
English
ReaderWriterLockSlim is a lightweight implementation of ReaderWriterLock. It represents a lock that can be used to manage protected resources in a way that allows multiple threads to share read access while allowing only one thread write access.
The following example uses ReaderWriterLockSlim to protect access on a list that is shared by three reader threads and one writer thread:
static ReaderWriterLockSlim _readerWriterLockSlim = new ReaderWriterLockSlim();static List<int> _list = new List<int>();private static void ReaderWriteLockSlim(){ Task writerTask = Task.Factory.StartNew( WriterTask); for (int i = 0; i < 3; i++) { Task readerTask = Task.Factory.StartNew(ReaderTask); }}static void WriterTask(){ for (int i = 0; ...Read now
Unlock full access