Synchrionization

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
C

csharpula csharp

I have a critical section and 3 procceses,2 of them can be at the same
time in the section.
I use mutex and doing it the followong way below,but it's not working.

How to make it work or maybe to do it in other way ?? Thank you very
much!

Here is the code:
//Function before the critical section:
// Info is singlecall which is mutual to all classes
Start()
{
Guid index=new Guid();
numberofPro =Info.Instance.numberofPro ;
if(numberOfPro >0)
{
Info.Instance.Mutex.ReleaseMute(Info.Instance.known_index);
}
index=Info.Instance.Mutex.AskMutex();
numberofPro ++;
Info.Instance.numberofPro =numberofPro;

}

End()
{
int numberofPro = Info.Instance.numberofPro ;
numberofPro--;
Guid index=new Guid(Info.Instance.known_index);
if(numberofPro==0)
{
Info.Instance.Mutex.ReleaseMutex(index);
}
Info.Instance.known_index=numberofPro ;
}

//Function in the end of critical section:
 
Hi,

It is hard to tell if there is something wrong with your code because the
code you posted doesn't show anything about how the mutex is used. What we
see is calling some custom methods e.g
Info.Instance.Mutex.ReleaseMutex(index) and Info.Instance.Mutex.AskMutex();

You should better post a simple compilable sample that demonstrates the
problem that we can easily compile and run.
 
Back
Top