I have a threaded server application that stores List<Item> dataList. There is a single writing thread that modifies, adds and removes items from the list, and multiple threads that read from this list.
What kind of synchronization is required to ensure the writes happen in order as they were called and provide maximum performance for the reads i.e. if a write is busy reads must just provide the previous value before the read.
I currently use ReaderWriterLockSlim for it’s separate Read and Write locking capabilities, but it feels as though there is a lot of expensive overhead calling the ReadLocks that is unnecessary since all I want is for writes to be guaranteed in order?
As far as I understand reading reference types and value types should provide atomic access so locking is perhaps not necessary?
Performance is a big concern and it seems like optimization of my synchronization structure could improve by quite a bit.
Sounds like you have a producer/consumer pattern. In .Net 4, there is the ConcurrentQueue<T> class in the
System.Threading.Concurrentnamespace. You are only synchronising when adding and removing from queue.