Original Post
Hello, I have a multithreaded Windows server application where multiple users are being served simultaneously by separate threads, which are all performing similar tasks (serving the same in-memory data, loading data from disk, saving out data, etc). My question is how to effectively and efficiently synchronize the threads to share in-memory data without conflict. Throughout development of this server, I have been trying to use critical sections (the standard Win32 object) as little as possible -- however I am not sure if my efforts are worthwhile or not. I am concerned with the idea that a critical section must lock the multiprocessor bus to perform synchronization (which is my understanding of it). I want synchronization to impact performance as little as possible -- to the point that I have been maintaining duplicating resources in memory for the threads that need them, so each has a unique pointer to its own version of the data. I am beginning to question whether or not I am acting correctly in limiting my use of critical sections; how much of a hit does entering and leaving critical sections over and over realistically incur on performance? For example, say you have a linked list of data structures and you add and remove items from it very irregularly, but the list is accessed often by all threads. I feel hesitant to lock every read of the list so that the rare writing operation does not affect the reading operations. What would be the best approach to handle the scenario above? Thank you! Jon