Hi all:

Just want to confirm the process that I employed to use this "critical section" feature of Microsoft Visual Studio is correct.

Say, there are two processes that I want to protect.

Codes:
while(1st process is active)
{
InitializeCriticalSection(&cs);
EnterCriticalSection(&cs);
Do something;
LeaveCriticalSection(&cs);
DeleteCriticalSection(&cs);
}

while (2nd process is active)
{
InitializeCriticalSection(&cs);
EnterCriticalSection(&cs);
Do something;
LeaveCriticalSection(&cs);
DeleteCriticalSection(&cs);
}

Thanks

I would do something like this

const n=...;(*number of processes*);
procedure P(i:integer);
[B]begin[/B]
   [B]repeat[/B]
         entercritical(R);
         <critical section>;
         exitcritical(R);
         <remainder>
   [B]forever[/B]
[B]end;[/B]
[B]begin[/B](*main program*)
   [B]parbegin[/B]
         P(1);
         P(2);
         P(3);
         -
         -
        P(n);
   [B]parend[/B]
[B]end[/B]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.