并发和切片迭代

huangapple go评论82阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2012年1月6日 08:24:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/8751880.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定