package main
import (
"fmt"
"sync"
"time"
)
var producer = func(wg *sync.WaitGroup, l sync.Locker) {
defer wg.Done()
for i := 5; i > 0; i-- {
l.Lock()
time.Sleep(1)
l.Unlock()
}
}
//observer := func(wg *sync.WaitGroup, l sync.Locker) {
// defer wg.Done()
// l.Lock()
// defer l.Unlock()
//}
//time.Duration
func Test() {
var duration_Milliseconds time.Duration = 500 * time.Millisecond
//var duration_Seconds time.Duration = (1250 * 1000000) * time.Millisecond
var duration_Seconds time.Duration = (60 * 12 * 60) * time.Second
var duration_Minute time.Duration = 2 * time.Minute
fmt.Printf("Milli [%v]\nSeconds [%v]\nMinute [%v]\n", duration_Milliseconds, duration_Seconds, duration_Minute)
}
var test = func(count int, mutex sync.Locker) {
var wg sync.WaitGroup
fmt.Println("niha")
wg.Add(1)
beginTestTime := time.Now().Second()
fmt.Println(beginTestTime)
go producer(&wg, mutex)
//fmt.Println(time.Now() - beginTestTime)
//return (time.Now().Second() - beginTestTime) * time.Second()
}
func main() {
var mutex sync.Locker
test(5, mutex)
//Test()
}
输出:
niha
55
标签:wg,duration,sync,timeDuration,var,time,go,fmt
From: https://www.cnblogs.com/heris/p/17179436.html