Synchrionization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • csharpula csharp

    #1

    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.M utex.ReleaseMut e(Info.Instance .known_index);
    }
    index=Info.Inst ance.Mutex.AskM utex();
    numberofPro ++;
    Info.Instance.n umberofPro =numberofPro;

    }

    End()
    {
    int numberofPro = Info.Instance.n umberofPro ;
    numberofPro--;
    Guid index=new Guid(Info.Insta nce.known_index );
    if(numberofPro= =0)
    {
    Info.Instance.M utex.ReleaseMut ex(index);
    }
    Info.Instance.k nown_index=numb erofPro ;
    }

    //Function in the end of critical section:





    *** Sent via Developersdex http://www.developersdex.com ***
  • Stoitcho Goutsev \(100\)

    #2
    Re: Synchrionizatio n

    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.M utex.ReleaseMut ex(index) and Info.Instance.M utex.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" <csharpula@yaho o.com> wrote in message
    news:ev5KlOhGGH A.376@TK2MSFTNG P12.phx.gbl...[color=blue]
    >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.M utex.ReleaseMut e(Info.Instance .known_index);
    > }
    > index=Info.Inst ance.Mutex.AskM utex();
    > numberofPro ++;
    > Info.Instance.n umberofPro =numberofPro;
    >
    > }
    >
    > End()
    > {
    > int numberofPro = Info.Instance.n umberofPro ;
    > numberofPro--;
    > Guid index=new Guid(Info.Insta nce.known_index );
    > if(numberofPro= =0)
    > {
    > Info.Instance.M utex.ReleaseMut ex(index);
    > }
    > Info.Instance.k nown_index=numb erofPro ;
    > }
    >
    > //Function in the end of critical section:
    >
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***[/color]


    Comment

    Working...