Originally posted by JosAH
C++ thread exceptions problem
Collapse
X
-
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... -
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
-
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.Originally posted by weaknessforcatsI 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.
And even if You were right, why on earth does this work fine under Linux?Comment
-
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
-
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?Originally posted by weaknessforcatsI 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
-
That isn't the problem; of course writing to a single static location from twoOriginally posted by Denis KukharevWell, 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?
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,
JosComment
-
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....Originally posted by JosAHThat 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,
JosComment
-
Despite my failure to find it as a known bug, there is a bugreport on this issue:Originally posted by Denis KukharevTo 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....
I' ve been pointed to it on another forum.
Will try to patch!
Thanks a lot! :)Comment
-
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,
JosComment
-
The problem has vanished after applying the patch!Originally posted by JosAHBe sure to apply the correct patch because they don't seem to agree on the
correctness of the patches themselves as well ;-)
kind regards,
JosComment
Comment