Skip to content

Commit

Permalink
Practice
Browse files Browse the repository at this point in the history
  • Loading branch information
mskKandula committed Nov 3, 2023
1 parent ada07dc commit 265c262
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Locks/main.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 265c262

Please sign in to comment.