Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timing wheel data race #12

Open
wllenyj opened this issue May 23, 2018 · 3 comments
Open

timing wheel data race #12

wllenyj opened this issue May 23, 2018 · 3 comments

Comments

@wllenyj
Copy link

wllenyj commented May 23, 2018

w.tv1[index] = vec[0:0:defaultTimerSize]

for _, t := range vec {

tv[i] = append(tv[i], t)

@siddontang
Copy link
Owner

Thank you @wllenyj

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

@wllenyj
Copy link
Author

wllenyj commented May 24, 2018

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
Copy link
Author

wllenyj commented May 24, 2018

another one, should add sync/atomic

w.jiffies++

t.expires = w.jiffies + uint64(when/w.tick)

t.expires = w.jiffies + uint64(when/w.tick)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants