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
runtime/cgo: deadlock #24608
Comments
Where's the mutex unlock? |
@cznic |
After root causing this, I've determined that the for loop is simply creating too many os threads too quickly due to cgo calls. So I believe this is user error? @cznic Simplified repo below:
|
@YijinLiu, it does look like your example program is creating goroutines faster than it can retire them. Do you have a more realistic example that properly bounds the number of goroutines in flight? Otherwise, I don't think there's anything for us to fix here. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.9.2 and 1.10
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
Calling Go from native code may cause deadlock if it holds some mutex that is needed by another CGO call. The following code calls CGO to increase a native counter, which is protected by a mutex.
if you pass "1" to C.inc_counter, it'll call Go to print the counter.
////////////////////////////// main.go //////////////////////////
//////////////////////////////////// inc_counter ////////////////////////////////////
What did you expect to see?
The program should run till I interrupt it.
What did you see instead?
It's killed by the system because it uses too many threads.
The printCounter Go call is stuck here (go1.9.2):
The text was updated successfully, but these errors were encountered: