Class SelectClaim
ChannelSelect,
or a lone channel operation) commits exactly one outcome between them.
A claim is a three-state machine: OPEN, PENDING, or COMMITTED. PENDING is a
revertible reservation held while a two-party pairing (a send offer meeting
a receive offer, each belonging to a different selection) verifies that both
sides still stand; the reservation always resolves promptly — its holder does
only lock-free work, never completes a future and never takes a lock while
holding it — so competitors may spin on it. When two claims must be reserved
together they are taken in ascending id order, which keeps every
waits-for chain strictly increasing and therefore cycle-free: the
shared-memory form of the commit protocol for generalized (input and output)
guards of Buckley & Silberschatz (TOPLAS 1983).
A committed claim records the winning party — the completion of the branch that won, or the cancelled marker — so cancellation can distinguish "this branch won, refuse the cancel: its delivery is imminent or done" from "a sibling won, this loser may unpark freely".
- Since:
- 6.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanallowCancel(Object future) Gate for cancelling the given parked completion.voidCommits a reservation made withpend(); cannot fail while the token is held.booleanWhether the claim has reached a terminal state (a reservation in flight is not terminal).pend()Reserves this claim, waiting out any other party's reservation.static intpendBoth(SelectClaim a, SelectClaim b, Object[] tokens) Reserves two parties' claims, in ascending id order regardless of argument order, reverting the first if the second turns out committed.voidReverts a reservation made withpend(), reopening the claim.booleanCommits in one step when no partner needs verifying: a value provably present under the channel lock, or a send into free buffer space.booleanCommits to cancellation: once this succeeds, no branch can deliver.
-
Constructor Details
-
SelectClaim
public SelectClaim()
-
-
Method Details
-
pend
Reserves this claim, waiting out any other party's reservation.- Returns:
- the token to
commit(java.lang.Object, java.lang.Object)orrevert(java.lang.Object)with, ornullif the claim is already committed
-
commit
Commits a reservation made withpend(); cannot fail while the token is held.- Parameters:
token- the reservation tokenwinner- the completion of the branch that won
-
revert
Reverts a reservation made withpend(), reopening the claim.- Parameters:
token- the reservation token
-
tryCommit
Commits in one step when no partner needs verifying: a value provably present under the channel lock, or a send into free buffer space.- Parameters:
winner- the completion of the branch that won- Returns:
falseif the claim was already committed elsewhere
-
tryCommitCancel
public boolean tryCommitCancel()Commits to cancellation: once this succeeds, no branch can deliver.- Returns:
falseif a branch had already won
-
isCommitted
public boolean isCommitted()Whether the claim has reached a terminal state (a reservation in flight is not terminal). -
allowCancel
Gate for cancelling the given parked completion. A still-open claim is committed to the cancel and the future may die; a claim committed to a sibling lets this loser unpark freely; but the committed winner itself is refused — its delivery is imminent or done and must reach the caller.- Parameters:
future- the completion being cancelled- Returns:
- whether the future may be cancelled
-
pendBoth
Reserves two parties' claims, in ascending id order regardless of argument order, reverting the first if the second turns out committed.- Parameters:
a- the first party's claim; its token lands intokens[0]b- the second party's claim; its token lands intokens[1]tokens- receives the two reservation tokens on success- Returns:
- 0 with both reservations held, 1 if
ais already committed, 2 ifbis
-