360 Secure SkillHub
360 安全技能中心

principle-separate-before-serializing-shared-state

针对多个并发执行者可能写入同一文件、分支、键或状态对象的场景,提供设计原则:优先让每个执行者独占自己的状态并在读取时合并,只有在单一共享写目标是真实不变量时才用锁、单写者或顺序阶段做结构化串行化。

分类:开发
mdsmithaustin
热度 0.00
最近更新 2026-11-26 11:31:40

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add mdsmithaustin/pstack/principle-separate-before-serializing-shared-state
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
principle-separate-before-serializing-shared-state
description
Apply when concurrent actors might write to the same file, branch, key, or state object. Eliminate the sharing first; serialize structurally only when one shared writer is a real invariant.

Separate Before Serializing Shared State

When concurrent actors might write the same file, branch, key, or object, first ask whether they need one shared object or are publishing independent facts. Default to giving each actor its own file, key, branch, or state directory, and merge only where the state is read. Two workers writing their own field into one state.json is still shared mutation.

Only when one shared write target is a real invariant, serialize access structurally (a lockfile, a single writer, sequential phases, compare-and-swap). Instructions are not concurrency control, and "we need a lock" is a smell to check first.