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

About client_manager mutex #104

Open
pathbox opened this issue Jan 15, 2018 · 0 comments
Open

About client_manager mutex #104

pathbox opened this issue Jan 15, 2018 · 0 comments
Labels

Comments

@pathbox
Copy link

pathbox commented Jan 15, 2018

Hi~
I read the code of client_manager.go, and I have a question about mutex. For example:

one part:

func (m *ClientManager) Add(client *Client)

...
m.mu.Unlock()
m.removeOldest()
m.mu.Lock()

two part:

func (m *ClientManager) removeOldest() {
	m.mu.Lock()
	ele := m.ll.Back()
	m.mu.Unlock()
	if ele != nil {
		m.removeElement(ele)
	}
}

func (m *ClientManager) removeElement(e *list.Element) {
	m.mu.Lock()
	defer m.mu.Unlock()
	m.ll.Remove(e)
	delete(m.cache, e.Value.(*managerItem).key)
}

It seems that it can not need "two" m.mu.Lock ?

The below codes are right?
func (m *ClientManager) Add(client *Client)

...
m.removeOldest()

If I just use m.mu.Lock once, it is not good for high concurrency?

Can you answer me about this question?

I appreciate it

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

No branches or pull requests

2 participants