Skip to content

Commit 91cdb5f

Browse files
committed
Just a littel cleanup in STM-code
1 parent 834e944 commit 91cdb5f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: _drafts/2024-12-26-STM-code.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ First, we don't try to barge unless we have been around for a while. A little p
729729
member private _.bargeTimeElapsed = (int64 Environment.TickCount) - startTime > BargeWaitTicks
730730
```
731731

732-
Second, we only barge the other transaction if we are older. This compares start points instead of read points, so this dates back to the first attempts of each transaction, not the current retry of each. (To determine who is older, look at dates of birth, not who had the most recent birthday.) The `compareAndSet` uses an `Interlocked` method. Why might this fail? The other transaction was running just before we got here. Well, someone else may have barged it, or it may already be committing or have committed or somehow gotten aborted. In those cases, even if it might be okay to proceed, it's too hard to tell, so let's just retry (via the block-and-bail that will follow). If we do barge, we trigger the latch on the other transaction's `LTInfo` on our way out. More on this in a minute (actually, 100 milliseconds).
732+
Second, we only barge the other transaction if we are older. This compares start points instead of read points, so this dates back to the first attempts of each transaction, not the current retry of each. (To determine who is older, look at dates of birth, not who had the most recent birthday.) The `compareAndSet` uses an `Interlocked` method. Why might this fail? The other transaction was running just before we got here. But from then now until now, someone else may have barged it, or it may already be committing or have committed or somehow gotten aborted. In those cases, even if it might be okay to proceed, it's too hard to tell, so let's just retry (via the block-and-bail that will follow a failed barge attempt). If we do barge, we trigger the latch on the other transaction's `LTInfo` on our way out. More on this in a minute (actually, 100 milliseconds).
733733

734734
The block-and-bail operation is short:
735735

@@ -763,8 +763,8 @@ The `stop` call does some cleanup to get us ready for the a retry.:
763763

764764
Next we wait (at least for a little bit) for the other transaction's latch to count down.
765765
Why wait? We just decided to block-and-bail. This only happens when we've run into a conflict and we've lost the battle.
766-
If we just barreled through and started our retry immediately, the other transaction might not have had time to finish and quit running (either completely or that iteration) -- we'd just get locked again. Why not just wait? Why is the latch involved?
767-
Well, if the other transaction gets barged or if it transitions itself to a new state (this happens in `stop`), the latch will count down. That can release us to proceed more quickly than `LockWaitMsecs`.
766+
If we just barreled through and started our retry immediately, the other transaction might not have had time to finish and quit running (either completely or just its current iteration) -- we'd just get locked again. Why not just wait? Why is the latch involved?
767+
Well, if the other transaction gets barged or if it transitions itself to a new state (this happens in `stop`), the latch will count down. That can release us to proceed more quickly than the full `LockWaitMsecs`.
768768

769769
### Do not fear commitment
770770

0 commit comments

Comments
 (0)