Thanks to visit codestin.com
Credit goes to github.com

Skip to content

list add method is not correct #79

@someview

Description

@someview

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions