package main import ( "container/list" "fmt" "os" "sync" "time" ) type INFO struct { lock sync.Mutex Name string Time int64 } var List *list.List = list.New() func main() { var Info INFO go func() { time.Sleep(1e9 * 30) os.Exit(1) }() go func() { for i := 0; i < 100; i++ { time.Sleep(1e8) Info.lock.Lock() Info.Name = fmt.Sprint("Name", i) Info.Time = time.Now().Unix() Info.lock.Unlock() List.PushBack(Info) } }() go Getgoods() select {} } func Getgoods() { time.Sleep(1e9) for List.Len() > 0 { if N, T := List.Remove(List.Front()).(INFO).name(); time.Now().Unix()-T >= 1 { fmt.Println(N) } } Getgoods() } func (i INFO) name() (string, int64) { return i.Name, i.Time }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-12 08:14:40