package main
import (
"fmt"
"time"
)
const (
total = 100
)
//Printer1
func Printer1(a, b chan int) {
for i := range a {
if i > 100 {
return
}
fmt.Printf("Printer1--%d\r\n", i)
b <- i + 1
}
}
func Printer2(a, b chan int) {
for i := range a {
if i > 100 {
return
}
fmt.Printf("Printer2--%d\r\n", i)
b <- i + 1
}
}
func main() {
a := make(chan int)
b := make(chan int)
go Printer1(a, b)
go Printer2(b, a)
a <- 0
time.Sleep(time.Millisecond * 10) //阻塞
close(a)
close(b)
fmt.Printf("exit\n")
}
面试汇总
这几年经历过不少面试,记录下来,偶尔看看,每次体验应该都会不一样吧。
某电商/平台容器调度
在线编程题
由于时间有限,写的比较仓促,基本满足要求。
Printer1--1 Printer2--2 Printer1--3 Printer2--4