Confused about the usage of Critical Section ..
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Confused about the usage of Critical Section ..

Threaded View

  1. #1
    Join Date
    Jan 2012
    Location
    India
    Posts
    138

    Confused about the usage of Critical Section ..

    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 ..
    Last edited by new_2012; December 12th, 2012 at 04:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center