What does Atomic Locks for Many Windows conclude, in numbers, about “After the Power Cut: Empty Locks, Missing Status and Write-Temporary-then-Link”?

Answer: Program p31 shows that when a claim is cut short by a power failure, the original method can leave 7 disk states in the lagging model, 3 of them empty locks; flushing reduces empty locks to 1 kind but cannot remove it; write-temporary-then-link brings them to zero. Program p32 shows that the cleaning rule "delete empty locks" gives a double claim in 10 of 25 schedules, and looking twice before deleting only lowers the share from 0.400 to 0.250. The best treatment of the half-finished remains of a power cut is to keep them from ever appearing in a living window. There is, however, a harder case: a window that has not lost power but has merely paused and will wake up later. Leases were designed for this case. Are they good enough for many windows?

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, 0.400, 10, 25

writercleanerschedulesdoubleshare
create, writenone500.000
create, writeempty once25100.400
create, writeempty twice40100.250
temp + linknone400.000
temp + linkempty once1100.000
temp + linkempty twice1600.000
Show the full program
# Chapter 3. p32: "an empty lock file is an orphan" is unsafe, because a
# live claimant passes through the empty state between create and write.
# A writer W races a cleaner H that deletes empty locks and then claims.
# The lock is (inode, content); W writes through its own open handle,
# so after H deletes the name W's bytes land on an unlinked inode and W
# still believes it holds. Every interleaving is counted exactly.
from functools import lru_cache

W_PLAIN = ("w_create", "w_write", "hold")
W_LINK = ("w_link", "hold")          # write temp first, then link()
H_ONCE = ("h_read", "h_clean", "h_create", "hold")
H_TWICE = ("h_read", "h_read", "h_clean", "h_create", "hold")


def step(op, who, lock, seen):
    """Return (new lock, new seen, still running)."""
    if op == "w_create":
        return (("w", "") if lock is None else lock), seen, lock is None
    if op == "w_write":
        if lock is not None and lock[0] == "w":
            lock = ("w", "W")
        return lock, seen, True
    if op == "w_link":
        return (("w", "W") if lock is None else lock), seen, lock is None
    if op == "h_read":
        empty = lock is not None and lock[1] == ""
        return lock, seen + (empty,), True
    if op == "h_clean":
        if seen and all(seen):
            return None, seen, True
        return lock, seen, True
    if op == "h_create":
        return (("h", "H") if lock is None else lock), seen, lock is None
    return lock, seen, True


def count(wprog, hprog):
    progs = (wprog, hprog)

    @lru_cache(maxsize=None)
    def walk(lock, pcs, seen):
        live = [i for i in (0, 1)
                if pcs[i] is not None and pcs[i] < len(progs[i])]
        if not live:
            held = [1 for i in (0, 1) if pcs[i] == len(progs[i])]
            return 1, (1 if len(held) == 2 else 0)
        tot = bad = 0
        for i in live:
            nl, ns, ok = step(progs[i][pcs[i]], i, lock, seen)
            npcs = list(pcs)
            npcs[i] = pcs[i] + 1 if ok else None
            t, b = walk(nl, tuple(npcs), ns)
            tot += t
            bad += b
        return tot, bad
    return walk(None, (0, 0), ())


print("writer          cleaner           schedules  double  share")
for wn, w in (("create, write", W_PLAIN), ("temp + link", W_LINK)):
    for hn, h in (("none", ("h_create", "hold")),
                  ("empty once", H_ONCE), ("empty twice", H_TWICE)):
        tot, bad = count(w, h)
        print("%-15s %-16s %9d %7d  %5.3f" % (wn, hn, tot, bad,
                                              bad / 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 3: After the Power Cut: Empty Locks, Missing Status and Write-Temporary-then-Link. 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