google / btree

BTree provides a simple, ordered, in-memory data structure for Go programs.
Apache License 2.0
3.97k stars 420 forks source link

only one goroutine put and some other goroutines get , Is it safe ? #23

Closed zhengxiaochuan-3 closed 6 years ago

zhengxiaochuan-3 commented 6 years ago

In go doc ,says "Write operations are not safe for concurrent mutation by multiple goroutines, but Read operations are."
But I don`t kown is this safe : "only one goroutine put and some other goroutines get" ,should I lock it ?

gconnell commented 6 years ago

Read operations are guaranteed not to modify internal state, so any number of reads can be done concurrently. However, writes do modify internal state, and a write should not be done concurrently with another write OR read.

In your specific case, since you're doing a write you should lock.