Locking pattern to protect a critical List<> with many worker threads
-
Fine. You're not wrong, but you didn't have to be an ass about it. But that's nothing new for you.
-
My program contains a List<T> object that is extremely critical to the program's function. In normal use, it will be accessed by many ( >10 ) worker threads. I don't need to synchronize worker thread access, because the workers never write to the collection, it's read-only to the worker threads. However, I want to be able to make changes to the list in a single, central class. And I'd like to be able to temporarily shut off worker-thread access to the list while changes are being made by a thread in the central class. I'd like not to require the worker threads to acquire a mutex every time they need access due to performance reasons. So, is there a pattern by which I can make access to the List<T> very fast for the worker threads, but still be able to shut off worker access while the list is being updated by the central class?
The difficult we do right away... ...the impossible takes slightly longer.
In addition to what others have mentioned, could you not provide an EventHandler to notify of List Changing?
-
In addition to what others have mentioned, could you not provide an EventHandler to notify of List Changing?
You didn't complete the thought. What benefit would come from what you recommend?
The difficult we do right away... ...the impossible takes slightly longer.
-
You didn't complete the thought. What benefit would come from what you recommend?
The difficult we do right away... ...the impossible takes slightly longer.
You can use an EventHandler in conjunction with a EventWaitHandle to inform the worker thread that the list has changed and pass the new list so that the worker thread is always working with the new list rather than an old list.