Skip to content

Commit

Permalink
Race Detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mskKandula committed Oct 30, 2023
1 parent d3b7a5f commit f9ca2ee
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Race/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"fmt"
"runtime"
"sync"
)

func main() {

counter := 0

const num = 15
var wg sync.WaitGroup
wg.Add(num)

for i := 0; i < num; i++ {
go func() {
temp := counter
runtime.Gosched()
temp++
counter = temp
wg.Done()
}()
}
wg.Wait()
fmt.Println("count:", counter)
}

0 comments on commit f9ca2ee

Please sign in to comment.