07 2020 档案
摘要:reflect包中的具体方法 reflect.TypeOf、reflect.ValueOf可以将一个普通的变量转换成『反射』包中提供的Type和Value type Person struct { Name string Sex string } func (p *Person) Add(a, b
阅读全文
摘要:sync.Mutex 保证共享资源的互斥访问 mutex := &sync.Mutex{} mutex.Lock() // Update共享变量 (比如切片,结构体指针等) mutex.Unlock() sync.RWMutex 读写互斥锁,可以对读加锁 mutex := &sync.RWMutex
阅读全文
摘要:sync.Pool 主要通过减少GC来提升性能,是Goroutine并发安全的 sync.Pool使用 初始化Pool实例,可以通过配置new方法来声明Pool元素创建的方法 bufferpool := &sync.Pool { New: func() interface {} { println(
阅读全文