关于「并发控制:独占新建锁、租约、版本号与分波次调度」,《多窗口写书防漂移》给出的定量结论是什么?

结论:检查与新建必须是一个原子动作,否则四个窗口同时起跑时,双重占有在所有交错里占 0.8571。抢章节的冲突随窗口数急剧上升,九章四窗口同时挑,撞车概率已是 0.5391;加锁让重复草稿归零,写手表让责任可追,两者叠加使用。租约用来回收失联者的锁,长短由心跳丢失率和时钟偏差决定;回收只准改名再新建,并用取锁序号挡住迟到的写入。共享文件比对版本号,重试过多就分片;人人都要的锁一律排号;多把锁按全局次序拿。章节之间的依赖拆出第零波,关键路径因此从 22 缩到 17。复盘用逻辑时钟排序,不用墙上时钟追责。下一章转向这些机制所保护的那张术语锁表本身。

数据口径:书中未标出处的错误率都是假设参数或合成数据上的测量值;本书不是法律意见,也不推荐任何写作工具或模型。 第八章让四个窗口并发写一本九章合成书,注入五类共 119 个错误:四道闸门拦住 0.723,漏网的 33 个里有 28 个属于机器在结构上看不见的手法,扣除后检出率为 0.945;干净书上术语检测首轮误报 1672 处,人审 48 个词后归零;一份严肃的注入审计每类至少要 75 个错误。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 与结论吻合的打印值: 17, 22

Kahn waves: 1 | 2,3,4,5,6,7 | 8 | 0
total work 50 ticks; critical path: chapters 22 ticks, with wave 0 17 ticks
none-waveviolationswaveslistwave0+list
2263333333
3194272727
4158262622
61210222220
查看完整验算程序
# Chapter 2. p25: Wave scheduling for a nine-chapter book: one big wave, strict waves, a term-table wave 0.
# Durations are invented ticks for a fictitious book. Prerequisites: chapters 2-7 need chapter 1 (it fixes
# the locked terms), chapter 8 needs 1-7, the preface 0 needs 8. Policies on n windows:
#   one-wave  : start anything in chapter order, ignore prerequisites (count starts before a prereq ends)
#   waves     : Kahn levels; a wave starts only when the previous wave is complete
#   list      : prerequisite-respecting list scheduling, longest remaining path first
#   wave0+list: split a 1-tick term-lock table T out of chapter 1; chapters 1-7 then need only T
DUR = {"0": 3, "1": 6, "2": 6, "3": 5, "4": 6, "5": 7, "6": 5, "7": 6, "8": 6}
DEP = {"0": ["8"], "1": [], "8": [str(i) for i in range(1, 8)]}
DEP.update({str(i): ["1"] for i in range(2, 8)})


def levels(dep):
    lvl, left = {}, dict(dep)
    k = 0
    while left:
        ready = sorted(t for t, ds in left.items() if all(d in lvl for d in ds))
        for t in ready:
            lvl[t] = k
            del left[t]
        k += 1
    return lvl


def tail(dur, dep):
    succ = {t: [s for s, ds in dep.items() if t in ds] for t in dep}
    memo = {}

    def f(t):
        if t not in memo:
            memo[t] = dur[t] + max((f(s) for s in succ[t]), default=0)
        return memo[t]
    return {t: f(t) for t in dep}


def list_schedule(dur, dep, n, respect=True):
    prio = tail(dur, dep)
    order = sorted(dep, key=lambda t: (-prio[t], t)) if respect else sorted(dep, key=lambda t: t)
    free = [0] * n
    end, start = {}, {}
    for _ in range(len(dep)):
        cands = [t for t in order if t not in end
                 and (not respect or all(d in end for d in dep[t]))]
        w = min(range(n), key=lambda i: free[i])
        best = None
        for t in cands:
            ready = max([free[w]] + ([end[d] for d in dep[t]] if respect else []))
            if best is None or ready < best[0]:
                best = (ready, t)
        s, t = best
        start[t], end[t] = s, s + dur[t]
        free[w] = end[t]
    viol = sum(1 for t in dep for d in dep[t] if start[t] < end[d])
    return max(end.values()), viol


def waves(dur, dep, n):
    lvl = levels(dep)
    clock = 0
    for k in sorted(set(lvl.values())):
        sub = {t: [] for t in dep if lvl[t] == k}
        span, _ = list_schedule(dur, sub, n)
        clock += span
    return clock


if __name__ == "__main__":
    lvl = levels(DEP)
    print("Kahn waves:", " | ".join(",".join(sorted(t for t in lvl if lvl[t] == k))
                                    for k in sorted(set(lvl.values()))))
    dur2 = dict(DUR, T=1)
    dep2 = {t: list(ds) for t, ds in DEP.items()}
    dep2["T"] = []
    dep2["1"] = ["T"]
    for i in range(2, 8):
        dep2[str(i)] = ["T"]
    print("total work {} ticks; critical path: chapters {} ticks, with wave 0 {} ticks".format(
        sum(DUR.values()), max(tail(DUR, DEP).values()), max(tail(dur2, dep2).values())))
    print("  n  one-wave  violations  waves  list  wave0+list")
    for n in (2, 3, 4, 6):
        ow, v = list_schedule(DUR, DEP, n, respect=False)
        print("  {}  {:>8}  {:>10}  {:>5}  {:>4}  {:>10}".format(
            n, ow, v, waves(DUR, DEP, n), list_schedule(DUR, DEP, n)[0], list_schedule(dur2, dep2, n)[0]))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《多窗口并行写书防漂移控制、术语跨卷一致性图审计与零幻觉文献核验器》第 2 章「并发控制:独占新建锁、租约、版本号与分波次调度」(版本 0.1.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-152 · v0.1.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026152,
  author    = {Fan, Yafu},
  title     = {Drift Control for Parallel Multi-Window Book Writing, Cross-Volume Terminology Graph Audits and Zero-Hallucination Citation Verifiers},
  year      = {2026},
  publisher = {5D Library},
  edition   = {0.1.0},
  note      = {DOI pending}
}

本书其他章节结论