Go从入门到实战——sync.Pool对象缓存(笔记)

sync.Pool对象获取

在这里插入图片描述

  • 私有对象是协程安全的,共享池是协程不安全的
  • 私用对象不用使用锁,共享池需要使用锁

sync.Pool对象放回

在这里插入图片描述

代码实例

在这里插入图片描述

sync.Pool对象的生命周期

在这里插入图片描述

sync.Pool总结

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42094659/article/details/107742208