英文:
Concurrency and slice iteration
问题
我有一个只读的对象切片。
很多并发的goroutine将会迭代这个切片来找到其中的某个对象并使用它。
这个切片是严格只读的,它只在应用程序启动时被写入一次,之后再也不会被写入。
当迭代这个切片时,并发的goroutine会相互干扰吗?(我需要应用读锁吗?)
英文:
I have a read-only slice of objects of a certain type.
A lot of concurrent goroutines will iterate over this slice to find a certain object in it and use it.
This slice is strictly read-only, it is written to only once (when the application is launched) and then never again.
Will concurrent goroutines interfere with each other when iterating over the slice? (Do I need to apply a read-lock?)
答案1
得分: 4
据我所知,只要切片是只读的,就没有问题。读取切片不会改变它。
英文:
To the best of my knowledge, as long as the slice is read-only, there's no problem. Reading a slice does not mutate it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论