-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
goroutine hangs at runtime.Gosched() #12553
Comments
My guess is your program is hanging because the garbage collector cannot run, and the garbage collector cannot run because all goroutines have not stopped. |
Dup of #10958 |
@randall77 Is this issue really duplicated with #10958? Here I'm wondering why it hangs, while in #10958, I doubt the precise preempt happens at the newstack() but not every function call. |
Yes. As Dave said, GC eventually tries to run, successfully stops the goroutine running test2, and then hangs forever trying to stop the goroutine that is doing for { test() }. |
Why removing time.Now() from test2() works? Because then the whole program running would not trigger GC? |
Removing time.Now() from test2 doesn't work for me. The program still hangs after a while (~250K iterations). Bottom line, don't write loops like this. Add runtime.Gosched() if you don't have anything else significant in the loop. |
If performance is a concern unroll the loop or add an inner loop. Until we On Wed, Sep 9, 2015 at 11:38 AM, Keith Randall [email protected]
|
Yes, removing the time.Now() doesn't work. Then the backtrace would be:
Thanks for your advises. I'm still wondering, the preemption check only happens at newstack(), right? |
@kingluo this issue is closed. If you want to discuss it further, please open a thread on the golang-nuts mailing list. |
Preemption checks happen at every function entry point, except those functions which don't have a preemption check (those with small stack frames, not recursive, ...). The preemption check causes the function entry to call into morestack and then newstack where the preemption is processed. |
The go version is
1.5.1
.Here is the program:
Note that I configure two threads to run goroutines.
The main goroutine would block one thread, while the test2() goroutine would run in another thread.
However, the result is that, the test2() runs a bit, but after some random interval, it hangs (do not output anything); the main goroutine continue to run test() without problem.
If I add some function call into the test(), e.g.
Then the test() and test2() would run in parallel as expected.
I try to do panic after some counts (estimated to be after the test2() hangs) within the loop to call test():
Then it shows the backtrace:
So why test2() goroutine hangs?
The text was updated successfully, but these errors were encountered: