This is not so, possibly wrong. Tools such as the Intel Parallel Inspector, which provide additional diagnostics for your program, must compromise between false positives and false negatives, in which case it seems that the developers thought that accessing the stack of another thread was much more likely than an error (low false positive rate, if reported) than not (high false negative rate, if not reported).
Valgrind is another example of a tool that can correctly signal code errors.
The real question here is: "What is the other thread doing?" If you think: “it may return from this function and the stack frame will be invalid”, then you are not performing parallel programming correctly. No response about multithreaded behavior should be qualified with the help of "maybe." You must make sure that this thread does not return, for example, by forcing it to wait for a change or condition variable, or by combining with other threads.
Discussion
Pubby: "AFAIK is very inefficient."
The only reason this would be inefficient is because you may have multiple cores that change the same cache lines, which is the same problem as other types of shared memory.
Collin: How do you know that the stack stack is still good in another thread?
If you use something in multiple threads, you use some kind of synchronization mechanism to make sure that it has not been changed incorrectly. This situation is no different.
H2CO3: Well, is there a reason you should not go to another person’s house?
If we play with analogues, I would say that the process is a house, and each of the flows is people in the house. If Dave keeps a list of duties in his room, I will go to his room every time I need to look at the list. If he stops doing this, he’d better tell me, or I will start writing on random papers on my desk.
Conclusion
It is a matter of style whether the behavior of this program is acceptable or not.
Dietrich epp
source share