GithubHelp home page GithubHelp logo

Race condition about haxmap HOT 6 OPEN

G-M-twostay avatar G-M-twostay commented on May 27, 2024
Race condition

from haxmap.

Comments (6)

G-M-twostay avatar G-M-twostay commented on May 27, 2024 1

@alphadose https://secondboyet.com/Articles/LockFreeLinkedList3.html is a better explanation. https://github.com/G-M-twostay/Go-Utils/blob/master/Maps/ChainMap/Node.go.
Harris's linked list originally used pointer tagging in C++, but unfortunately that's impossible in Go in my knowledge due to garbage collection.

from haxmap.

alphadose avatar alphadose commented on May 27, 2024

@G-M-twostay understood, I will take a look at this. Might be related to #23

from haxmap.

G-M-twostay avatar G-M-twostay commented on May 27, 2024

If I were correct about the race condition, then to solve it, simply enforce consistency between node.next and node.delete. One such way is to make use an additional struct to combine these 2 fields and directly operate on the immutable struct.

from haxmap.

alphadose avatar alphadose commented on May 27, 2024

@G-M-twostay I couldn't understand your solution completely. Can you give me an example code snippet ?

from haxmap.

ItalyPaleAle avatar ItalyPaleAle commented on May 27, 2024

I am looking at haxmap but am a bit concerned by this issue. After playing with it a bit, it appears it may be related to a race condition while resizing.

I can repro the error easily with @G-M-twostay's code, even as a Test and not a Benchmark. But, if I allocate the haxmap with a larger initial capacity, the error does not appear.

// Old
M := haxmap.New[int, int]()
// New
M := haxmap.New[int, int](iter0 * elementNum0)

-- EDIT

It looks like this is a known "issue". I just saw this in the docs:

If a resizing operation is happening concurrently while calling Set() then the item might show up in the map only after the resize operation is finished

from haxmap.

G-M-twostay avatar G-M-twostay commented on May 27, 2024

I am looking at haxmap but am a bit concerned by this issue. After playing with it a bit, it appears it may be related to a race condition while resizing.

I can repro the error easily with @G-M-twostay's code, even as a Test and not a Benchmark. But, if I allocate the haxmap with a larger initial capacity, the error does not appear.

// Old
M := haxmap.New[int, int]()
// New
M := haxmap.New[int, int](iter0 * elementNum0)

-- EDIT

It looks like this is a known "issue". I just saw this in the docs:

If a resizing operation is happening concurrently while calling Set() then the item might show up in the map only after the resize operation is finished

I believe it's related to deletion.

from haxmap.

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.