I need to use some synchronization mechanism between two threads of a single process, I have used CRITICAL SECTION but it has drastically slow down the execution of the code, although apart of use of CRITICAL SECTION related API's in two threads my code has no other performance impacting use, Can anyone share how to use synchronization mechanism in windows ? The same part I have used under linux with the use of `mutex` which is working fine.
CRITICAL_SECTION cs;
INITIALIZECRITICALSECTION(cs);
Thread-1 Thread-2
while(1) { while(1) {
... ....
EnterCriticalSection(&cs); if ( TryEnterCriticalSection(&cs) ) {
.... ....
LeaveCriticalSection(&cs); LeaveCriticalSection(&cs);
.... } else {
} Sleep(1);
}
}
task of this threads are to manipulate some networking read/write stuff.
I have used NAT(network address translation for the ethernet interfaces and this threads are manipulating one of the interface) in windows xp, which is required purposefully .