Giter VIP home page Giter VIP logo

Comments (7)

drmingdrmer avatar drmingdrmer commented on May 18, 2024 1

You are right: right won't be GC-ed. I was wrong about it.

As you mentioned, the issue is that left or right has a chance it is already removed from the list when this method is called.

from hashmap.

cornelk avatar cornelk commented on May 18, 2024

Thanks for your bug report, indeed the old implementation had some issues, the current dev branch has a singly linked list which should not have those issues anymore. Please review and create a new ticket if you see any other issue, thanks!

from hashmap.

drmingdrmer avatar drmingdrmer commented on May 18, 2024

There is only a bug_grow_insert branch. Is it the dev branch you mentioned above?

from hashmap.

drmingdrmer avatar drmingdrmer commented on May 18, 2024

Since main branch is still the default branch, closing this issue without fixing it is inappropriate for users.

Please keep an issue of an unsolved problem open, to let users know there is a risk in using this lib.

from hashmap.

cornelk avatar cornelk commented on May 18, 2024

Main is the default/dev branch, tags are releases. Since the code now uses a singly linked list, this issue is not present or valid anymore and gets closed.

from hashmap.

drmingdrmer avatar drmingdrmer commented on May 18, 2024

I'm afraid the problem is still there as long as it uses a pointer address to identify an unchanged node:

The right has a chance it has been changed, but the address is the same.

Please keep this issue open until it's been fixed.

func (l *List[Key, Value]) insertAt(element, left, right *ListElement[Key, Value]) bool {
	if left == nil {
		left = l.head
	}

	element.next.Store(right)

	if !left.next.CompareAndSwap(right, element) {
		return false // item was modified concurrently
	}

	l.count.Add(1)
	return true
}

from hashmap.

cornelk avatar cornelk commented on May 18, 2024

Thanks for reviewing it again. I will reopen the issue once I can clearly see/understand the problem.

The only issue I can see here is that if the function insertAt returns false due to a concurrent change of the next pointer of the left node, the inserting should be retried but currently the callers do not do that. Is this what you are referring to?
Edit: HashMap.insertElement already does retry in case of concurrent interfering changes.

Other than that I can see no issue of using a pointer to identify a node. If there is still a reference/pointer to the node object, the GC should not garbage collect the object and reuse it.

from hashmap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.