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

fix(os/gcache): optimize locking mechanism in SetWithLock method #4153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wlynxg
Copy link
Contributor

@wlynxg wlynxg commented Feb 13, 2025

fix #4145

@@ -182,12 +182,13 @@ func (d *memoryData) SetMap(data map[interface{}]interface{}, expireTime int64)
}

func (d *memoryData) SetWithLock(ctx context.Context, key interface{}, value interface{}, expireTimestamp int64) (interface{}, error) {
d.mu.Lock()
defer d.mu.Unlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetWithLock方法的作用就是要在锁中执行用户给定的Func,建议参考我在issue中评论的方案。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我仔细思考了一下,感觉那个提问者说的对不同的 key 值进行锁定的方案可能会更好一些

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

Successfully merging this pull request may close these issues.

os/gcache: dead lock when another GetOrSetFuncLock in former GetOrSetFuncLock's f function
2 participants