multi threaded programming
Every one says multi thread programming is hard. Here is a way I think to reduce the problem.
Understand what is the critical data you are trying to protect.
Do you understand what happens if you just let different threads party on your data. If you do not understand this don’t go further.Understanding of this crucial in designing what kind of protection mechanisms you need.
After doing analysis in above two steps its pretty clear what you need to protect.
Single variable protection: An example of this is a state variable that can be set by multiple threads but you have a state machine to follow.This requires protection on this single variable to make we only do the valid transitions. Look at Interlocked* functions for this.
Complex data structure: For ex a list that needs to be read and modified. For this you want to look at critical section that protects the data structure against multiple threads.
More complex synchronization mechanisms include cross process coordination that requires Semaphores or mutexes. I never really needed this in my projects so far.
Comments
Post a Comment