From 265c262ae083f5ec4ff45628575be6395279b82b Mon Sep 17 00:00:00 2001 From: mskKandula Date: Fri, 3 Nov 2023 11:36:15 +0530 Subject: [PATCH] Practice --- Locks/main.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Locks/main.go diff --git a/Locks/main.go b/Locks/main.go new file mode 100644 index 0000000..89925ef --- /dev/null +++ b/Locks/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "fmt" + "sync" + "time" +) + +var ( + count int64 + wg sync.WaitGroup +) + +func inc() { + defer wg.Done() + + count += 1 + +} + +func dec() { + defer wg.Done() + + count -= 1 + +} + +func main() { + t1 := time.Now() + + for i := 0; i < 10000000; i++ { + wg.Add(2) + go inc() + go dec() + } + + wg.Wait() + fmt.Println(count, time.Since(t1)) +}