What does Atomic Locks for Many Windows conclude, in numbers, about “State Machines for Hand-Over between Windows: Transfer, Tokens and a Status That Only Moves Forward”?
Answer: Program p61 showed that hand-over by delete-then-create is overtaken by a third party in 40 of 54 schedules; atomic replacement removes the queue-jumping, yet 0.250 of schedules are still damaged by the departing window's late write; adding a token brings both loss and damage to zero. Program p62 showed that a blindly written status file moves backwards in 4 of 6 schedules, that reading before writing still moves backwards in 0.333 of them, and that one exclusive mark per stage never does. We have now tested the lock protocol of many-window collaboration, from claiming, power cuts, leases and orphan locks to hand-over, with the mathematics of the second half of the twentieth century. Yet exclusion and hand-over are not problems that began with computers. How were the keys of a city gate kept more than two thousand years ago? And what exactly does Dijkstra's single page say, and which of its statements can still be tested today? The next chapter returns to the classics.
Scope of the numbers: Marked boxes separate published evidence, runnable Python calculations (19 programs), classical sources and the author's hypotheses.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 0.250, 40, 54
| protocol | schedules | lost | share | damage | share |
|---|---|---|---|---|---|
| H1 delete, then B creates | 54 | 40 | 0.741 | 22 | 0.407 |
| H2 replace content, tell B | 28 | 0 | 0.000 | 7 | 0.250 |
| H3 replace + token, fenced | 28 | 0 | 0.000 | 0 | 0.000 |
Show the full program
# Chapter 6. p61: three ways for window A to hand a volume to window B
# while window C may try to claim it, and while one write of A's is
# still in flight (it may land at any later moment). Counted over all
# schedules: "lost" = B does not end up holding; "damage" = A's late
# write is the value left in the store after a newer write. Protocols:
# H1 delete the lock, then tell B to create it; H2 replace the lock's
# content with B atomically (temp + rename), then tell B; H3 as H2 but
# the content carries token 2 and the store refuses tokens below the
# highest it has seen. Everything lives in memory.
from functools import lru_cache
PROTOS = {
"H1 delete, then B creates": (("a_delete", "a_send", "a_late"),
("b_wait", "b_create", "b_write")),
"H2 replace content, tell B": (("a_give", "a_send", "a_late"),
("b_wait", "b_check", "b_write")),
"H3 replace + token, fenced": (("a_give", "a_send", "a_late"),
("b_wait", "b_check", "b_write")),
}
C_PROG = ("c_create", "c_write")
def run(name):
a, b = PROTOS[name]
progs = (a, b, C_PROG)
fenced = name.startswith("H3")
def write(store, val, tok):
cur, top, newer = store
if fenced and tok < top:
return store
newer = newer or val != "A"
return (val, max(top, tok), newer)
@lru_cache(maxsize=None)
def walk(lock, msg, store, pcs):
live = []
for i in range(3):
if pcs[i] is None or pcs[i] >= len(progs[i]):
continue
if progs[i][pcs[i]] == "b_wait" and not msg:
continue
live.append(i)
if not live:
lost = 0 if pcs[1] == len(b) else 1
dmg = 1 if store[0] == "A" and store[2] else 0
return 1, lost, dmg
tot = lost = dmg = 0
for i in live:
op, ok = progs[i][pcs[i]], True
nl, nm, ns = lock, msg, store
if op == "a_delete":
nl = None
elif op == "a_give":
nl = "B"
elif op == "a_send":
nm = True
elif op == "a_late":
ns = write(store, "A", 1)
elif op == "b_create":
ok = lock is None
nl = "B" if ok else lock
elif op == "b_check":
ok = lock == "B"
elif op == "b_write":
ns = write(store, "B", 2)
elif op == "c_create":
ok = lock is None
nl = "C" if ok else lock
elif op == "c_write":
ns = write(store, "C", 2)
npcs = list(pcs)
npcs[i] = pcs[i] + 1 if ok else None
t, l, d = walk(nl, nm, ns, tuple(npcs))
tot, lost, dmg = tot + t, lost + l, dmg + d
return tot, lost, dmg
return walk("A", False, ("A", 1, False), (0, 0, 0))
print("protocol schedules lost share damage share")
for name in PROTOS:
tot, lost, dmg = run(name)
print("%-28s %8d %5d %5.3f %6d %5.3f"
% (name, tot, lost, lost / tot, dmg, dmg / tot))Single source and citation
Fan, Y. (2026). Atomic File-Lock Protocols for Multiple Windows: Self-Recovering Orphan Locks after Power Loss and Cross-Window Hand-Over State Machines (Version 1.0.0), Chapter 6: State Machines for Hand-Over between Windows: Transfer, Tokens and a Status That Only Moves Forward. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 5DL-B-254 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026254,
author = {Fan, Yafu},
title = {Atomic File-Lock Protocols for Multiple Windows: Self-Recovering Orphan Locks after Power Loss and Cross-Window Hand-Over State Machines},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}Other chapter answers in this book
- Chapter 1 · The Race Window: Exhaustive Interleavings of Check-then-Create and Their Width on the Wall Clock
- Chapter 2 · Mutual Exclusion from Reads and Writes Alone: Model-Checking Six Entry Protocols and the Roster Bound
- Chapter 3 · After the Power Cut: Empty Locks, Missing Status and Write-Temporary-then-Link
- Chapter 4 · Leases, Clocks and Fencing Tokens
- Chapter 5 · Judging Orphan Locks: How Long a Silence Means Death
- Chapter 7 · Classical Sources East and West: the Gatekeeper Who "Keeps and Issues the Keys" and Dijkstra in 1965
- Chapter 8 · Closing the Loop: a Formal Health Check of This Series' Lock Protocol and a Pre-Registered Test