This is a created article in which the information may have evolved or changed.
<pre name= "code" class= "plain" >package mainimport ("container/list" "FMT" "Math/rand" "Sync" "Time") type INFO struct {lock sync. Mutexname stringtime Int64}var List *list. List = list. New () func main () {var Info infogo func () {for i: = 0; i < 5; i++ {time. Sleep (time. Duration (1E9 * Int64 (RAND). INTN (5))) Info.lock.Lock () Info.name = Fmt. Sprint ("Name", i) Info.time = time. Now (). Unix () + 3info.lock.unlock () List.pushback (Info)}} () go Getgoods () Select {}}func getgoods () {for {time. Sleep (1e8) for List.len () > 0 {N, T: = List.remove (List.front ()). ( INFO). Name () Now: = time. Now (). Unix () if T-now <= 0 {fmt. Println (N, T, now) continue}time. Sleep (time. Duration ((t-now) * 1e9)) fmt. Println (N, T, now)}}}func (i INFO) name (string, Int64) {return i.name, i.time}