[RFC] Resource.claim
as an alternative to raise
+ access
#30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this PR, instead of writing this:
You can write:
The latter form doesn't have the problem of over-raising the threshold (e.g. you
could have used
R2
instead ofR1
in theraise
example shown above). Thelatter form is also better for refactors. If you increase or decrease the
ceiling you don't have to change the
R1.claim
call. OTOH if you had code likethis:
and decided to change the ceiling of R1 to 2 then you would have had to change
the code to this:
The downside of exclusively using claim, which you have to do to get the
refactoring advantage, is the excessive rightward drift that comes from nesting
claim
calls:This could be addressed with a
multiclaim
macro (?) that lets you claimseveral methods at once.
Another downside (?) of using
claim
is that it hides the fact that accessing aresource may be creating a critical section. This makes it harder to visualize
the span of critical sections which makes it harder to estimate the blocking
time of a task (assuming you are not using tooling to analyze that).
The final downside is that, since this PR is adding
claim
instead ofdeprecating
raise
andaccess
in favor of it, we would end with two ways toaccess resource (TIMTOWTDI). This means that we would have to document both
methods and list their advantages and disadvantages, and that we would be
placing the burden of making a choice on users.
cc @perlindgren