-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: singleflight to return refcount vs shared bool #8
Conversation
…hich carries both boolean "shared" indicator as well as actual reference counter
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
This PR (HEAD: 8b166cb) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/sync/+/213478 to see it. Tip: You can toggle comments from me using the |
Message from Gobot Gobot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/213478. |
Message from Brad Fitzpatrick: Patch Set 1: (6 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/213478. |
This PR (HEAD: 91fa807) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/sync/+/213478 to see it. Tip: You can toggle comments from me using the |
91fa807
to
55a4369
Compare
This PR (HEAD: 55a4369) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/sync/+/213478 to see it. Tip: You can toggle comments from me using the |
declining this PR in favor of #9 |
Background:
We are using singleflight to run expensive procedure that creates a temporary resource (temp file)
Our challenge - we need to determine when it is safe to cleanup this temp resource
Currently
Group.Do/DoChan
calls only return ashared bool
indicator, but they do not surface to caller how many actual caller will be using this result.Proposal to consider:
Currently implementation maintains "dups int" property for each
call
, semantically it is almost exactly a "reference counter" except in case of single caller it holds value 0 instead of 1.I propose, to slightly change signature of
Group.Do
/DoChan
: in addition to "shared bool" also return the actual reference counter (pointer tocall.dups
?)This PR provides an implementation for above
In short it does 2 things:
refShared
type and changesGroup.Do
signature to use in lace ofshared bool
This slightly reduces duplicated code and will prevent a race condition on computation of
shared
flag. This race condition is introduced by previous item, as calculation ofshared bool
depends on valuecall.dups
and that value could get changed by caller now.Note
It might be easier to review this PR on per commit basis