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

list add method is not correct #79

Open
someview opened this issue Aug 26, 2023 · 0 comments
Open

list add method is not correct #79

someview opened this issue Aug 26, 2023 · 0 comments
Labels

Comments

@someview
Copy link

someview commented Aug 26, 2023

Now the add method code is like this:

func (l *List[Key, Value]) Add(searchStart *ListElement[Key, Value], hash uintptr, key Key, value Value) (element *ListElement[Key, Value], existed bool, inserted bool) {
	left, found, right := l.search(searchStart, hash, key)
	if found != nil { // existing item found
		return found, true, false
	}

	element = &ListElement[Key, Value]{
		key:     key,
		keyHash: hash,
	}
	element.value.Store(&value)
	return element, false, l.insertAt(element, left, right)
}

The problem exists :

element.value.Store(&value)
return element, false, l.insertAt(element, left, right)

This is not a atomic operation.The proposal atomicOp may solve this if atomicpointer with other metainfo is supported.

@someview someview added the bug label Aug 26, 2023
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

1 participant