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

Use sync.map replace mutex #83

Closed
zyfjeff opened this issue Jan 16, 2021 · 1 comment
Closed

Use sync.map replace mutex #83

zyfjeff opened this issue Jan 16, 2021 · 1 comment
Labels
kind/feature New feature or request waiting This issue requires fix from outside of this repo

Comments

@zyfjeff
Copy link
Contributor

zyfjeff commented Jan 16, 2021

What would you like to be added:

Use sync.map replace mutex, there are so many lock and unlock operations in our code that it's easy to forget that unlock causes deadlocks. Instead of mutex, use sync.map and atomic variable, Take the following code for example.

prefetch.go
mem_cache.go
.....

Why is this needed:

@zyfjeff zyfjeff added the kind/feature New feature or request label Jan 16, 2021
@davies
Copy link
Contributor

davies commented Jan 16, 2021

@zyfjeff sync.map could be used replace map, but we still need to make sure updating other counters are atomic.

Usually, defer l.Unlock() follower l.Lock(), so it's easy to use, and no deadlock at all, so I think this is the simple way to go.

@davies davies closed this as completed Jan 16, 2021
@xiaogaozi xiaogaozi added the waiting This issue requires fix from outside of this repo label Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request waiting This issue requires fix from outside of this repo
Projects
None yet
Development

No branches or pull requests

3 participants