go icon indicating copy to clipboard operation
go copied to clipboard

timing wheel data race

Open wllenyj opened this issue 6 years ago • 3 comments

https://github.com/siddontang/go/blob/2b7082d296ba89ae7ead0f977816bddefb65df9d/time2/wheel.go#L148 https://github.com/siddontang/go/blob/2b7082d296ba89ae7ead0f977816bddefb65df9d/time2/wheel.go#L154 https://github.com/siddontang/go/blob/2b7082d296ba89ae7ead0f977816bddefb65df9d/time2/wheel.go#L112

wllenyj avatar May 23 '18 12:05 wllenyj

Thank you @wllenyj

Do you think what is the best way to fix it? Maybe Lock?

siddontang avatar May 24 '18 00:05 siddontang

w.tv1[index] = make([]*timer, 0, defaultTimerSize)

or

var pool = &sync.Pool{
    New: func() interface{} {
        return make([]*timer, 0, defaultTimerSize)
    },
} 
w.tv1[index] = pool.Get().([]*timer)
f := func(vec []*timer) {
    //.....
    vec = vec[0:0:  defaultTimerSize]
    pool.Put(vec)
}

wllenyj avatar May 24 '18 06:05 wllenyj

another one, should add sync/atomic https://github.com/siddontang/go/blob/2b7082d296ba89ae7ead0f977816bddefb65df9d/time2/wheel.go#L145 https://github.com/siddontang/go/blob/2b7082d296ba89ae7ead0f977816bddefb65df9d/time2/wheel.go#L194 https://github.com/siddontang/go/blob/2b7082d296ba89ae7ead0f977816bddefb65df9d/time2/wheel.go#L204

wllenyj avatar May 24 '18 08:05 wllenyj