I looked into the source code of BlogEngine.NET. There are a lot of singleton pattern usages used for caching purpose. For example
the Post class has Posts static variable implemented as singleton that caches all posts available in a blog.
I believe the static variable is a shared resource. When accessed via web application, there could be many threads that access this
shared resource from many web requests. Then it makes sense when writing to the static variable, the Post class acquires lock on the _SyncRoot static variable. But I don’t see a lock attempt when modifying this shared resource, for example:
Post newPost = new Post();
newPost.Property1 = …;
Based on my understanding, altering shared resource is a non-thread-safe action. When we alter this shared resource, there could be
other threads reading on the same resource. But, I also understand that trying to acquire the same lock for reading operation is not the right solution since it will affect the performance of the application dramatically.
So, my question is why not using the reader-writer locking schema? Reader-writer schema is suitable here since the shared resource
will often be read than written.