C++ thread exceptions problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Denis Kukharev
    New Member
    • Aug 2008
    • 16

    #16
    Originally posted by JosAH
    Type 'where' without the quotes and pay special attention to the first column.

    kind regards,

    Jos
    And gdb will display call stack (Like the one demonstrated in the initial post). But I didn't catch how to see stack levels before throw and in catch block... Does this require manipulations with breakpoints and step-by-step executing? I'm not quite familiar with gdb yet, You know. And the idea of tracking this levels is not perfectly clear so far...

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #17
      I believe that rand uses a static variable so it can keep track of the previous random number. I expect all rand calls use the same static variable. That would be a shared resource that could cause a race condition.

      It's the same reason why you can't use strok in a multi-threaded environment.

      Comment

      • Denis Kukharev
        New Member
        • Aug 2008
        • 16

        #18
        Originally posted by weaknessforcats
        I believe that rand uses a static variable so it can keep track of the previous random number. I expect all rand calls use the same static variable. That would be a shared resource that could cause a race condition.

        It's the same reason why you can't use strok in a multi-threaded environment.
        I use rand_r in test with local variable to avoid static buffers. Anyway, fragments in real program where exceptions "hang" don't have static or lockable resources. But all of them produce the same stack after the application being killed with sig -11 upon hanging.
        And even if You were right, why on earth does this work fine under Linux?

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #19
          I can't say. I was just oberving that a remembered random value is a shared resource. There has to be a place where the seed value is kept. All threads will use that same place unless the thread is spawned so that it has private memory for it's heap, stack and static mambers.

          Comment

          • Denis Kukharev
            New Member
            • Aug 2008
            • 16

            #20
            Originally posted by weaknessforcats
            I can't say. I was just oberving that a remembered random value is a shared resource. There has to be a place where the seed value is kept. All threads will use that same place unless the thread is spawned so that it has private memory for it's heap, stack and static mambers.
            Well, explain Your guess about deadlock please. Is this the stack trace that provoked such a thought direction? Or accidental hanging of the application? Did You reproduce the test?

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #21
              Originally posted by Denis Kukharev
              Well, explain Your guess about deadlock please. Is this the stack trace that provoked such a thought direction? Or accidental hanging of the application? Did You reproduce the test?
              That isn't the problem; of course writing to a single static location from two
              different threads yield unpredictable results w.r.t. the value stored at that
              location but it can never make a thread hang up.

              Just to be sure, you could skip the random value, use a fixed value and see
              what happens on your BSD box ...

              kind regards,

              Jos

              Comment

              • Denis Kukharev
                New Member
                • Aug 2008
                • 16

                #22
                Originally posted by JosAH
                That isn't the problem; of course writing to a single static location from two
                different threads yield unpredictable results w.r.t. the value stored at that
                location but it can never make a thread hang up.

                Just to be sure, you could skip the random value, use a fixed value and see
                what happens on your BSD box ...

                kind regards,

                Jos
                To clear it up, I've tried to get rid of random usleep() and random numbers at all. The problem remained. And I tried to leave randoms and usleep() intact having commented throwign the exception. The test ran just fine. So, the problem is likely about exceptions....

                Comment

                • Denis Kukharev
                  New Member
                  • Aug 2008
                  • 16

                  #23
                  Originally posted by Denis Kukharev
                  To clear it up, I've tried to get rid of random usleep() and random numbers at all. The problem remained. And I tried to leave randoms and usleep() intact having commented throwign the exception. The test ran just fine. So, the problem is likely about exceptions....
                  Despite my failure to find it as a known bug, there is a bugreport on this issue:



                  I' ve been pointed to it on another forum.

                  Will try to patch!
                  Thanks a lot! :)

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #24
                    Originally posted by Denis Kukharev
                    Despite my failure to find it as a known bug, there is a bugreport on this issue:



                    I' ve been pointed to it on another forum.

                    Will try to patch!
                    Thanks a lot! :)
                    Be sure to apply the correct patch because they don't seem to agree on the
                    correctness of the patches themselves as well ;-)

                    kind regards,

                    Jos

                    Comment

                    • Denis Kukharev
                      New Member
                      • Aug 2008
                      • 16

                      #25
                      Originally posted by JosAH
                      Be sure to apply the correct patch because they don't seem to agree on the
                      correctness of the patches themselves as well ;-)

                      kind regards,

                      Jos
                      The problem has vanished after applying the patch!

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #26
                        Originally posted by Denis Kukharev
                        The problem has vanished after applying the patch!
                        Congrats; I sincerely hate it when the bug is to be found in the tools or libs.

                        kind regards,

                        Jos

                        Comment

                        Working...