package main
import (
"fmt"
"sync"
)
var slice = []string{"apple", "banana", "orange"}
var index int
var mutex sync.Mutex
func main() {
P()
P()
P()
}
func P() {
mutex.Lock()
defer mutex.Unlock()
index := index % len(slice)
fmt.Println(slice[index])
index++
}
评论