new*_*eee 6 go goroutine visual-studio-code delve
考虑下面的小片段:
package main
import (
"fmt"
"sync"
)
func main() {
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
for i := 1; i < 100; i++ {
fmt.Println("A:", i)
}
}()
go func() {
defer wg.Done()
for i := 1; i < 100; i++ {
fmt.Println("B:", i)
}
}()
wg.Wait()
}
Run Code Online (Sandbox Code Playgroud)
在 delve 中,我们可以使用以下命令轻松地在 goroutine 之间切换
goroutine
goroutine <id>
goroutine <id> <command>
Run Code Online (Sandbox Code Playgroud)
如果我想在 goroutine 1 中逐步运行,只需使用命令
goroutine 1 next
Run Code Online (Sandbox Code Playgroud)
在vscode中,似乎处理goroutines的唯一方法是调用堆栈,但是,这似乎是go runtime的内部线程,而不是goroutines,那么如何将运行过程集中在指定的goroutine中呢?
| 归档时间: |
|
| 查看次数: |
1215 次 |
| 最近记录: |