← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 4545.g.8.d.1.a

映射并发读写必须同步

理解等级:中级

HTTP服务可同时处理请求,普通map的读写不能因此自动安全。读写锁允许多个读取共享,但写入需独占;所有访问同一映射的路径都要遵守相同保护协议,包括删除。锁保护的是约定范围的数据,并不会顺带保护其他全局变量。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Building a Cloud Native Service · 查看原书依据

      Maps in Go are not atomic and are not safe for concurrent use. Unfortunately, we now have a service designed to handle concurrent requests that’s wrapped around exactly such a map. So what do we do? Well, typically when a programmer has a data structure that she needs to read from and write to from

    参考来源

    - 位置:《Cloud Native Go》第05章《Building a Cloud Native Service》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch05.xhtml) - 结论依据:HTTP服务可同时处理请求,普通map的读写不能因此自动安全。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:Maps in Go are not atomic and are not safe for concurrent use. Unfortunately, we now have a service designed to handle concurrent requests that’s wrapped around exactly such a map. So what do we do? Well, typically when a programmer has a data structure that she needs to read from and write to from