File: goroutinebreak.go

package info (click to toggle)
delve 1.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 15,084 kB
  • sloc: ansic: 111,947; sh: 194; asm: 147; makefile: 43; python: 23
file content (26 lines) | stat: -rw-r--r-- 425 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main

import "runtime"

const N = 10

func agoroutine(started chan<- struct{}, done chan<- struct{}, i int) {
	started <- struct{}{}
	done <- struct{}{}
}

func main() {
	done := make(chan struct{})
	started := make(chan struct{})
	for i := 0; i < N; i++ {
		runtime.Breakpoint()
		go agoroutine(started, done, i)
	}
	for i := 0; i < N; i++ {
		<-started
	}
	runtime.Gosched()
	for i := 0; i < N; i++ {
		<-done
	}
}