471,315 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

Synchrionization

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.know n_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:

*** Sent via Developersdex http://www.developersdex.com ***
Jan 15 '06 #1
1 1001
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.
--

Stoitcho Goutsev (100)

"csharpula csharp" <cs*******@yahoo.com> wrote in message
news:ev*************@TK2MSFTNGP12.phx.gbl...
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.know n_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:

*** Sent via Developersdex http://www.developersdex.com ***

Jan 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.