gomonkey icon indicating copy to clipboard operation
gomonkey copied to clipboard

并发不安全范围

Open hueng opened this issue 4 years ago • 2 comments

如下代码,并发访问getMockTime(),有安全问题吗?想确认下,我测试没发现并发问题。

func init() {
	gomonkey.ApplyFunc(time.Now, func() time.Time {
		mockTime := int64(1588239281376264700)

		sec := mockTime / 1000000000
		nsec := mockTime % 1000000000
		return time.Unix(sec, nsec)
	})
}

func getMockTime() {
         // output: 2020-04-30 17:34:41.3762647 +0800 CST
	fmt.Println("mock time:", time.Now())
}

hueng avatar May 07 '20 13:05 hueng

多读没有问题

agiledragon avatar Jul 07 '20 15:07 agiledragon

这个并发安不安全是看你自己的func实现吧

linqh1 avatar Jul 15 '20 09:07 linqh1