strange ???

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

    #1

    strange ???

    I have a piece of code which is in a multithread program:

    ....
    bool b,b1;
    b1 = MyData.success;
    //MyData is protected using Mutex, b1=true here by using Visual Studio
    watch window
    b = (b1 == true);//return false ??????
    b = (true && b1);//return true
    ....

  • Ben Pope

    #2
    Re: strange ???

    kathy wrote:[color=blue]
    > I have a piece of code which is in a multithread program:
    >
    > ...
    > bool b,b1;
    > b1 = MyData.success;
    > //MyData is protected using Mutex, b1=true here by using Visual Studio
    > watch window
    > b = (b1 == true);//return false ??????
    > b = (true && b1);//return true
    > ...[/color]

    We can't help you unless you post complete compilable code.
    Unfortunately, if you do that, it'll be off topic.

    Best bet is to ask in a newsgroup where multithreading on Windows is
    topical, perhaps somewhere in the public.microsof t.* hierarchy.

    Ben Pope
    --
    I'm not just a number. To many, I'm known as a string...

    Comment

    • Victor Bazarov

      #3
      Re: strange ???

      kathy wrote:[color=blue]
      > I have a piece of code which is in a multithread program:
      >
      > ...
      > bool b,b1;
      > b1 = MyData.success;[/color]

      Are you sure it's not

      b = MyData.success;

      here?
      [color=blue]
      > //MyData is protected using Mutex, b1=true here by using Visual Studio
      > watch window[/color]

      What's "Mutex"? (A hint: it's not topical here)
      [color=blue]
      > b = (b1 == true);//return false ??????
      > b = (true && b1);//return true
      > ...
      >[/color]

      This is covered by FAQ 5.8, I think.

      V
      --
      Please remove capital As from my address when replying by mail

      Comment

      • Andrew Koenig

        #4
        Re: strange ???

        "kathy" <yqin_99@yahoo. com> wrote in message
        news:1142359666 .655481.100460@ p10g2000cwp.goo glegroups.com.. .
        [color=blue]
        > bool b,b1;
        > b1 = MyData.success;
        > //MyData is protected using Mutex, b1=true here by using Visual Studio
        > watch window
        > b = (b1 == true);//return false ??????
        > b = (true && b1);//return true[/color]

        Without seeing all the code, it's impossible to know for sure...but could it
        be that MyData.success was never initialized? It is possible for
        uninitialized bool objects to take on values that are neither true nor false
        (because undefined behavior really means undefined, when anything can
        happen).


        Comment

        Working...