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

saw your post on reddit #1

Open
vmanyushin opened this issue Oct 3, 2018 · 1 comment
Open

saw your post on reddit #1

vmanyushin opened this issue Oct 3, 2018 · 1 comment

Comments

@vmanyushin
Copy link

func main3() {
	var n uint64

	if *ngoroutines == 0 {
		n = uint64(runtime.GOMAXPROCS(0))
	} else {
		n = uint64(*ngoroutines)
	}

	fmt.Println("GOMAXPROCS", n)

	result := make(chan uint64)
	var i uint64

	for i = 0; i < n; i++ {
		go func(i uint64) {
			var sum uint64
			var start = (LIMIT / n) * i
			var end = start + (LIMIT / n)

			for j := start; j < end; j++ {
				sum += j
			}
			result <- sum
		}(i)
	}

	var total uint64
	for i = 0; i < n; i++ {
		total += <-result
	}

	fmt.Println(total)
}
@vmanyushin vmanyushin changed the title see you post on reddit saw your post on reddit Oct 3, 2018
@ethomas2
Copy link
Owner

ethomas2 commented Oct 3, 2018

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants