golang-design / under-the-hood

📚 Go: Under The Hood | Go 语言原本 | https://golang.design/under-the-hood

Home Page:https://golang.design/under-the-hood

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sync pool 相关描述错误

Transme opened this issue · comments

实际描述

  • 文件路径:book/zh-cn/part1basic/ch05sync/pool.md
  • 原文段落:
我们来证明一下此处确实不会发生取到自身的情况,不妨设:pid = (pid+i+1)%size 则 pid+i+1 = a*size+pid。 即:a*size = i+1,其中 a 为整数。由于 i<size,于是 a*size = i+1 < size+1,则: (a-1)*size < 1 ==> size < 1 / (a-1),由于 size 为非负整数,这是不可能的。

预期描述

(a-1)*size < 1 ==> size < 1 / (a-1) 这段的描述有问题,当 a=1 时是没办法做除法的,源代码的做法并不能保证不取到自身,只能保证最后一个取到自己。

附图

image