Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: why there is no race condition in this case ? #39212

Closed
fkarakas opened this issue May 22, 2020 · 1 comment
Closed

Question: why there is no race condition in this case ? #39212

fkarakas opened this issue May 22, 2020 · 1 comment

Comments

@fkarakas
Copy link


import "time"

type counter struct {
	count []int
}

func main() {
	c := counter{}
	c.count = make([]int, 2)

	go func() {
		for i := 0; i < 1000; i++ {
			c.count[0] = i
		}
	}()

	go func() {
		total := 0
		for {
			total += c.count[1]
		}
	}()

	time.Sleep(15 * time.Second)
}
@ALTree
Copy link
Member

ALTree commented May 22, 2020

Accessing different elements of an array is not a race condition; each element counts as a separate variable.

We don't use the github issue tracker for asking questions about the language, so I'm closing here.

Please see the Questions wiki page; it has a list of good places for asking questions. Thanks.

@ALTree ALTree closed this as completed May 22, 2020
@golang golang locked and limited conversation to collaborators May 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants