逐行标记
贯穿 n07 的程序(一个小仓库),每行标了它碰的数据:
1 total = total + amount # 共享 total,写
2 log = [] # 本地
3 log.append("入库") # 本地
4 if stock >= need: # 共享 stock,读(检查)
5 stock = stock - need # 共享 stock,写(动作)
6 count = count + 1 # 共享 count,写
7 print(total) # 共享 total,只读
8 name = name.upper() # 本地按规则标记:碰共享数据的行标 Y,本地的标 n;再列出要保护的共享数据名(去重、按首次出现):
LINES = [(1, "total", "w"), (2, None, None), (3, None, None), (4, "stock", "r"), (5, "stock", "w"), (6, "count", "w"), (7, "total", "r"), (8, None, None)]
marks = "".join("Y" if v else "n" for _, v, _ in LINES)
shared = []
for _, v, _ in LINES:
if v and v not in shared:
shared.append(v)
print(marks + "/" + ",".join(shared))
全部评论