On Thu, Apr 2, 2020 at 9:38 AM <studyinglian...@gmail.com> wrote:
>
> Hi, I just read the commit from 
> https://go-review.googlesource.com/c/go/+/166960 and it said the reason to 
> use lock-free is because when using mutex  "Clearing must zero out the 
> pointer to every object in every Pool to prevent a concurrent slow path from 
> causing all objects to be retained. Since this happens during STW, this has 
> an O(# objects in Pools) effect on STW time."
> I just can't understand why concurrent Get and clearPool will cause all 
> objects to be retained. Thank in advance for any help!

Note that that comment is referring to the old code that that series
of changes is replacing.  See the implementation of poolCleanup in
1.12 or earlier.  In that older implementation, when pinSlow and
poolCleanup run simultaneously, it's possible for pinSlow to return an
entry to a pool that poolCleanup has already set to nil in the
allPools slice.  That would retain that pool pointer for as long as
the pointer returned by pinSlow was alive.  To avoid keeping
everything alive, poolCleanup clears the pointers.

Ian

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXMesC3MT45hrT42VOEykrb_goF_xFq-yBQ0oaPbbnoUQ%40mail.gmail.com.

Reply via email to