Question

I have a custom CMS in which I use an static XElement as the site map. When updates occur to the map, I am synchronizing the writer threads, but am doing nothing with the readers, just allowing them to grab the XElement when they need it.

In testing, I thought that if I was enumerating the XElement from a reader thread, while I updated it on another writing thread, I would get an exception. That was not the case. Just wondering if anyone can explain to me if they see any major issues with this approach. It doesn't seem like it should be safe, but all my testing so far has indicated that it is.

Was it helpful?

Solution

Use a System.Threading.ReaderWriterLock to control access to the XElement. That way you synchronise all readers and any writers without blocking concurrent read activity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top