摘要:
Pool 连接池 Pool 的另一个很常用的一个场景就是保持 TCP 的连接。一个 TCP 的连接创建,需要三次握手等过程,如果是 TLS 的,还会需要更多的步骤,如果加上身份认证等逻辑的话,耗时会更长。所以,为了避免每次通讯的时候都新创建连接,我们一般会建立一个连接的池子,预先把连接创建好,或者是 阅读全文
posted @ 2023-02-04 10:23
kohn
阅读(56)
评论(0)
推荐(0)
摘要:
Context 基本使用方法 type Context interface { Deadline() (deadline time.Time, ok bool) Done() <-chan struct{} Err() error Value(key interface{}) interface{} 阅读全文
posted @ 2023-02-04 10:22
kohn
阅读(102)
评论(0)
推荐(0)
摘要:
Cond 使用方法举例 func main() { c := sync.NewCond(&sync.Mutex{}) var ready int for i := 0; i < 10; i++ { go func(i int) { time.Sleep(time.Duration(rand.Int6 阅读全文
posted @ 2023-02-04 10:22
kohn
阅读(27)
评论(0)
推荐(0)
摘要:
Channel Channel 的应用场景 Don’t communicate by sharing memory, share memory by communicating. Go Proverbs by Rob Pike “communicate by sharing memory”和“sha 阅读全文
posted @ 2023-02-04 10:22
kohn
阅读(208)
评论(0)
推荐(0)
摘要:
atomic Mutex、RWMutex 等并发原语的实现,最底层是通过 atomic 包中的一些原子操作来实现的. 在很多场景中,使用并发原语实现起来比较复杂,而原子操作可以帮助我们更轻松地实现底层的优化. atomic 原子操作的应用场景 可以使用 atomic 实现自己定义的基本并发原语. 如 阅读全文
posted @ 2023-02-04 10:21
kohn
阅读(73)
评论(0)
推荐(0)
摘要:
Map 1 Go Map 的底层实现原理 Go 中 Map 是一个指针,指向 hmap 结构体。hmap 包含 buckets(Pointer) 和 oldbuckets(Pointer),Pointer 指针的地址是 bmap 数组作为 hash 表,散列的方式是将 bmap 连成链表来进行散列。 阅读全文
posted @ 2023-02-04 10:21
kohn
阅读(56)
评论(0)
推荐(0)