Created
April 21, 2020 12:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
var x = 0 | |
func sendNumber(wg *sync.WaitGroup, ch chan<- int, nump *int) { | |
ch <- *nump + x | |
wg.Done() | |
} | |
func main() { | |
var wg sync.WaitGroup | |
var num = 123 | |
var p = &num | |
wg.Add(1) | |
ch := make(chan int, 1) | |
go sendNumber(&wg, ch, p) | |
wg.Wait() | |
num = 789 | |
fmt.Println(<-ch) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment