Skip to content
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 involving signals #4833

Closed
dvyukov opened this issue Feb 17, 2013 · 4 comments
Closed

runtime/cgo: deadlock involving signals #4833

dvyukov opened this issue Feb 17, 2013 · 4 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Feb 17, 2013

darwin/amd64, the following program deadlocks:

package main

import "C"

import (
    "fmt"
    "runtime"
    "time"
)

func main() {
    runtime.GOMAXPROCS(100)
    ping := make(chan bool)
    go func() {
        for i := 0; ; i++ {
            select {
            case done := <-ping:
                if done {
                    fmt.Printf("\n")
                    ping <- true
                    return
                }
                fmt.Printf(".")
                ping <- true
            default:
            }
            func() {
                defer func() {
                    recover()
                }()
                var s *string
                *s = ""
            }()
        }
    }()
    time.Sleep(time.Millisecond)
    for i := 0; i < 64; i++ {
        go func() {
            runtime.LockOSThread()
            select {}
        }()
        go func() {
            runtime.LockOSThread()
            select {}
        }()
        time.Sleep(time.Millisecond)
        ping <- false
        select {
        case <-ping:
        case <-time.After(time.Second):
            fmt.Printf("HANG\n")
            return
        }
    }
    ping <- true
    select {
    case <-ping:
    case <-time.After(time.Second):
        fmt.Printf("HANG\n")
        return
    }
}
@dvyukov
Copy link
Member Author

dvyukov commented Feb 17, 2013

Comment 1:

It was pure fun to debug, especially taking into account that it shows only with new
scheduler, small tests w/o cgo all work and gdb does not work.
I will mail the fix https://golang.org/cl/7324058 once
https://golang.org/cl/7322086 is in (it's needed for cgo tests).

@rsc
Copy link
Contributor

rsc commented Feb 19, 2013

Comment 2:

Yuck. CL 7322086 is already LGTMed, fwiw.

@dvyukov
Copy link
Member Author

dvyukov commented Feb 20, 2013

Comment 3:

Yeah, but 7322086 depends on 7304102 (ensure forward progress of runtime.Gosched()),
otherwise tests hang...

@dvyukov
Copy link
Member Author

dvyukov commented Feb 25, 2013

Comment 4:

This issue was closed by revision 4eb7ba7.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants