954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

About critical section

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

yuzhang
Light Poster
43 posts since May 2006
Reputation Points: 10
Solved Threads: 0
 

I would do something like this

const n=...;(*number of processes*);
procedure P(i:integer);
<strong>begin</strong>
   <strong>repeat</strong>
         entercritical(R);
         <critical section>;
         exitcritical(R);
         <remainder>
   <strong>forever</strong>
<strong>end;</strong>
<strong>begin</strong>(*main program*)
   <strong>parbegin</strong>
         P(1);
         P(2);
         P(3);
         -
         -
        P(n);
   <strong>parend</strong>
<strong>end</strong>
SpS
Posting Pro
599 posts since Aug 2005
Reputation Points: 70
Solved Threads: 32
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You