To our great surprise we found recently this. With SP1 for Windows 2003 Microsoft changed a way critical sections behave. Earlier threads wanting to access them were served in FIFO manner. Right now they are served in pure "random" way.
In our case we had something like this:
// I now it's kind of ugly design but works
void Class:RunInThread()
{
while(m_Running)
{
EnterCriticalSection(&m_CS);
DoSomeStuffWithList();
LeaveCriticalSection(&m_CS);
}
}
void Class::AddToList()
{
EnterCriticalSection(&m_CS);
AddSomeStuffToList();
LeaveCriticalSection(&m_CS);
}
So with new implementation of critical section in 2003 SP2 AddToList might die in starvation since there is no guarantie that it will be awaken.
This example is a little bit extreme but on the other hand I have millions lines of code that were written with assumption that access to critical sections is serialized.
Is there a way to turn off this new critical section?
EDIT: Since getting back old version is not possible I am thinking of just doing global Search&Replace to change {Enter,Leaver}CriticalSection into something like My{Enter,Leave}CriticalSection. Have you ideas how this should be implemented so it behaves exactly like pre-SP2 version ?