cornelk / hashmap

A Golang lock-free thread-safe HashMap optimized for fastest read access.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

list add method is not correct

someview opened this issue · comments

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.