360 Secure SkillHub
360 安全技能中心

principle-separate-before-serializing-shared-state

针对并发 actor 可能写同一文件、分支、键或状态对象的情况,指导优先为各 actor 分配独立状态并仅在读取处合并;仅当单一共享写目标确为不变量时,才用锁、单写者、顺序阶段或比较交换进行结构化序列化。

分类:开发
michael-denyer
热度 0.00
最近更新 2026-11-25 17:33:03

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add michael-denyer/pstack-claude/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.
user-invocable
false

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.