Skip to content

goroutine with sync #1

Description

@pikachule
package main

import (
	"fmt"
	"sync"
)

func cal(a, b int, n *sync.WaitGroup) {
	c := a + b
	fmt.Printf("%d + %d = %d\n", a, b, c)
	defer n.Done()
}

func main() {
	var go_sync sync.WaitGroup
	for i := 0; i < 100; i++ {
		go_sync.Add(1)
		go cal(i, i+1, &go_sync)
	}
	go_sync.Wait()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions