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

@fkarakas fkarakas commented May 22, 2020


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 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 May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.