Created
March 8, 2023 12:28
-
-
Save fzdwx/825f29e8da6f97451e17099055e3d0e9 to your computer and use it in GitHub Desktop.
This file contains 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" | |
) | |
func main() { | |
for n := 0; n < 10; n++ { | |
var ( | |
count = 1 | |
n = 1000000 | |
wg = sync.WaitGroup{} | |
) | |
wg.Add(2) | |
for i := 0; i < 2; i++ { | |
go func() { | |
defer wg.Done() | |
for j := 0; j < n; j++ { | |
count++ | |
} | |
}() | |
} | |
wg.Wait() | |
fmt.Println(count) | |
} | |
} | |
// output: | |
// 1378924 1133362 1031662 1031665 1090521 1221675 1266065 1157836 1326654 1023312 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment