Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3029

Confused about the usage of Critical Section ..

$
0
0
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 ..

Viewing all articles
Browse latest Browse all 3029

Latest Images

Trending Articles



Latest Images