Race condition: getting multiple threads to cooperate
I'm currently writing a server program that listens for incoming incoming network transport and spawns a new thread for each new connection.
Now all these threads will be accessing a certain function at several different times, and while one thread is calling the function I want to block the other threads from executing the same code at the same time to prevent possible (nowever unlikely or uncritical) race conditions. Is there some simple method of doing this? I want the solution to be robust as I expect the program to be running for months on end without stopping.
The program is intended for the win2k/xp platform and want it to complie no trouble in both VC6+ and BC5+.