Object pool thread safety?
Closed this issue · 2 comments
resurtm commented
Hi @yksz!
https://github.com/yksz/go-design-patterns/blob/master/creation/object_pool.go
Is this code thread safe? For example:
func (p *ObjectPool) ReturnObject(object *PooledObject) {
fmt.Printf("Return: %s\n", object)
p.idle.PushBack(object)
p.remove(p.active, object)
}
Shouldn't both these list operations must be enclosed into sync.RWMutex
lock for thread safety?
Cheers,
@resurtm
yksz commented
I think you're right.
It should be locked into ReturnObject() and BorrowObject().
I'm gonna fix these methods.
Thank you.