I am using a thread in my application .. A DLL is written for In and Out instructions for hardware ICS and to read FIFO.
My code is
CCriticalSection crdll , crsec ;
UINT ThreadReceiveData(LPVOID param)
{
for ( ; ; ) {
if (bTerminate) break; // bTerminate = 1 in Doc template destructor
crdll.Lock();
do {
read data ;
if ( data is not valid) break;
crdll.Lock();
if (data of type 1) process data;
crdll.Unlock();
crsec.Lock();
if (data of type 2) process data;
crsec.Unlock();
} while valid data
crdll.UnLock();
}
return 1;
}
I am confused , how and when I should use Ctitical Section ? The program works fine but I am
not happy as this is main routine of the program and I have not understood it properly.
PL GUIDE ..
My code is
CCriticalSection crdll , crsec ;
UINT ThreadReceiveData(LPVOID param)
{
for ( ; ; ) {
if (bTerminate) break; // bTerminate = 1 in Doc template destructor
crdll.Lock();
do {
read data ;
if ( data is not valid) break;
crdll.Lock();
if (data of type 1) process data;
crdll.Unlock();
crsec.Lock();
if (data of type 2) process data;
crsec.Unlock();
} while valid data
crdll.UnLock();
}
return 1;
}
I am confused , how and when I should use Ctitical Section ? The program works fine but I am
not happy as this is main routine of the program and I have not understood it properly.
PL GUIDE ..