FAQ
I'm trying to implement a concurrent list. Many goroutines should be able
to add, remove, and traverse nodes at the same time.
Here's the code <https://gist.github.com/nhjk/df740315ec8f4cac99de>.
I'm getting the error "panic: sync: unlock of unlocked mutex" when I try to
remove all the nodes using the Filter function.
Here's the test code <https://gist.github.com/nhjk/159aec69157b2757bbd3> where
I get the error.
This only happens for 2000+ nodes (on my computer, may vary). Same for
1,000,000 etc. However, running it on 1000 works perfectly fine.

Through liberal use of print statements and manual unlocking instead of
defering (side note: on panic it would be nice if it showed the defered
function it paniced on instead of the enclosing function) I've determined
that the unlock it panics on is an unlock of a prev node in the remove
function. I don't know where to go from here.

Here's an illustration of how the remove function works on node c in list a
<-> b <-> c <-> d <-> e, red represents a locked node

a <-> b <-> c <-> d <-> e first lock the prev
node (b)
a <-> b <-> c <-> d <-> e then the node you want
to remove (c)
a <-> b <-> c <-> d <-> e then the next node (d)

now set b.next to d and d.prev to b, and nil everything on c to prevent
memory leaks resulting in
c
a <-> b <-> d <-> e
let defers handle unlocking
c
a <-> b <-> d <-> e


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Andrew Bursavich at Dec 8, 2014 at 5:01 am
    There's a race. The node that gets locked on line 78 isn't necessarily the
    same node that's stored in prev on line 79 and then subsequently unlocked.

    That was fun :)

    Cheers,
    Andy

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 8, '14 at 3:08a
activeDec 8, '14 at 5:01a
posts2
users2
websitegolang.org

2 users in discussion

Kalpaxisn: 1 post Andrew Bursavich: 1 post

People

Translate

site design / logo © 2022 Grokbase