← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 4545.g.3.e

通道与锁按责任选择

理解等级:中级

通道适合传递所有权、分发离散工作或返回异步结果,锁适合保护缓存等大块共享状态。二者都属于协调工具,不应因偏好某句格言就强行替换。选择让职责和同步边界最清楚的方案,并说明通信后谁仍能访问数据。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Scalability · 查看原书依据

      Channels shine when you’re working with many discrete values, and are the better choice for passing ownership of data, distributing units of work, or communicating asynchronous results. Mutexes, on the other hand, are ideal for synchronizing access to caches or other large stateful structures. At the end of the day, no tool solves every problem.

    参考来源

    - 位置:《Cloud Native Go》第07章《Scalability》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch07.xhtml) - 结论依据:通道适合传递所有权、分发离散工作或返回异步结果,锁适合保护缓存等大块共享状态。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。 - 原始内容:Channels shine when you’re working with many discrete values, and are the better choice for passing ownership of data, distributing units of work, or communicating asynchronous results. Mutexes, on the other hand, are ideal for synchronizing access to caches or other large stateful structures. At the end of the day, no tool solves every problem.