关于「实证闭环:本百卷锁协议的形式化体检与预注册方案」,《多窗口原子锁》给出的定量结论是什么?
结论:第八章对本百卷正在使用的锁协议做形式化体检:原样零双领,加自动清理者则 48 个终止状态有 45 个双领;给出蒸馏小工具「锁协议竞态穷举器」与预注册方案,零失败证明双领率低于千分之一需 2995 批。书中以标注框区分已发表的证据、可运行的 Python 计算(19 段程序)、原典与作者的假说。
数据口径:书中参数为示意;全部计算由书中程序生成;程序不读写任何文件;本书是非个人化经营建议,任何锁协议的上线变更与孤儿锁裁决须由主事者人工复核放行。 本书把协议的每一步写成原子操作,在内存里模拟文件系统,穷举全部交错调度,并修正蓝图四处:「必有」说的是调度空间,两窗口 16 种调度有 12 种双领,墙钟上的频率取决于出发是否扎堆,四个窗口 2 秒内一拥而上时每批 0.02966;迪杰斯特拉 1965 年恰恰证明只靠读写也能互斥,限制在于名册必须封闭;围栏令牌出自伯罗斯的序列号与克莱普曼的整理,不出自格雷与切里顿;单调计时挡不住进程停顿,时钟完美时仍有 0.000976 的写入迟到。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 45, 48
| variant | states | ends | double | no-status | unclaimed |
|---|---|---|---|---|---|
| as written | 111 | 3 | 0 | 0 | 0 |
| power cuts | 535 | 111 | 0 | 83 | 87 |
| check-then-create | 368 | 7 | 4 | 0 | 4 |
| auto cleaner | 2133 | 48 | 45 | 0 | 0 |
查看完整验算程序
# Chapter 8. p81: a formal health check of this century's claim protocol
# (exclusive-create B-xxx.lock, then write B-xxx.status = drafting;
# forward windows ascend, reverse windows descend, held numbers are
# skipped; orphans go to a human). Four volumes; forward windows F1
# (quota 2) and F2 (quota 1), reverse window R (quota 1). Every
# reachable state is explored in memory. Variants: as written; with
# power cuts (any window may die at any step); with check-then-create;
# with an automatic cleaner that re-claims any lock lacking a status.
from collections import deque
V = 4
WINS = (("F1", 2, False), ("F2", 1, False), ("R", 1, True))
def order(rev):
return list(range(V - 1, -1, -1)) if rev else list(range(V))
def explore(mode):
n = len(WINS) + (1 if mode == "cleaner" else 0)
# 窗口状态:(位置, 已领数, 阶段, 存活);阶段 0 待建锁,1 待写状态,
# 2 已检查待创建(先检查后创建变体)
start = (tuple([None] * V), tuple([False] * V),
tuple([frozenset()] * V), tuple([(0, 0, 0, True)] * n))
seen, todo, ends = {start}, deque([start]), []
while todo:
s = todo.popleft()
lock, stat, bel, ws = s
nxt = []
for w in range(n):
pos, got, ph, alive = ws[w]
if w == len(WINS): # 自动清理者:扫一遍
if pos >= V or not alive:
continue
L, S, B = list(lock), list(stat), list(bel)
if L[pos] is not None and not S[pos]:
L[pos], S[pos] = w, True
B[pos] = B[pos] | {w}
nxt.append((tuple(L), tuple(S), tuple(B),
put(ws, w, (pos + 1, got, 0, True))))
continue
name, quota, rev = WINS[w]
if not alive or got >= quota or pos >= V:
continue
if mode == "power":
nxt.append((lock, stat, bel,
put(ws, w, (pos, got, ph, False))))
vol = order(rev)[pos]
L, S, B = list(lock), list(stat), list(bel)
if ph == 1:
S[vol] = True
st = (pos + 1, got + 1, 0, True)
elif mode == "check" and ph == 0:
st = (pos, got, 2, True) if L[vol] is None else \
(pos + 1, got, 0, True)
elif L[vol] is None or ph == 2:
L[vol] = w
B[vol] = B[vol] | {w}
st = (pos, got, 1, True)
else:
st = (pos + 1, got, 0, True)
nxt.append((tuple(L), tuple(S), tuple(B), put(ws, w, st)))
if not nxt:
ends.append(s)
for t in nxt:
if t not in seen:
seen.add(t)
todo.append(t)
return seen, ends
def put(t, k, v):
t = list(t)
t[k] = v
return tuple(t)
print("variant states ends double no-status unclaimed")
for mode, name in (("plain", "as written"), ("power", "power cuts"),
("check", "check-then-create"),
("cleaner", "auto cleaner")):
seen, ends = explore(mode)
dbl = len([e for e in ends if max(len(b) for b in e[2]) >= 2])
nos = len([e for e in ends
if any(l is not None and not s
for l, s in zip(e[0], e[1]))])
unc = len([e for e in ends if None in e[0]])
print("%-16s %6d %5d %7d %10d %10d"
% (name, len(seen), len(ends), dbl, nos, unc))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《多窗口文件原子锁并发协议、断电孤儿锁自愈与跨窗口交接状态机母典》第 8 章「实证闭环:本百卷锁协议的形式化体检与预注册方案」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 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}
}