Created
November 14, 2011 19:26
-
-
Save dgrijalva/1364867 to your computer and use it in GitHub Desktop.
Runaway deadlocked goroutines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
"time" | |
) | |
func main() { | |
go count() | |
for { | |
spawn() | |
time.Sleep(1e9) | |
} | |
} | |
func count() { | |
for { | |
fmt.Printf("Currently running %v goroutines\n", runtime.Goroutines()) | |
time.Sleep(1e9) | |
} | |
} | |
func spawn() { | |
c := make(chan int, 1) | |
go wait(c) | |
} | |
func wait(c chan int) { | |
<- c | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment