Skip to content

Commit

Permalink
Merge branch 'main' into relicense
Browse files Browse the repository at this point in the history
  • Loading branch information
GrosQuildu committed Jul 14, 2023
2 parents 00bc7ea + a13c350 commit 16db752
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
33 changes: 33 additions & 0 deletions go/anonymous-race-condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,36 @@ func AnonRaceCond_4_FP() {

wg.Wait()
}


func AnonRaceCond_5() {
var wg sync.WaitGroup
// ok: anonymous-race-condition
for idx, val := range values {
wg.Add(1)
idx, val := idx, val
go func() {
val.s.Method("test")
fmt.Println("Completed index", idx)
wg.Done()
}()
}

wg.Wait()
}

func AnonRaceCond_6() {
var wg sync.WaitGroup
// ok: anonymous-race-condition
for idx, val := range values {
wg.Add(1)
idx, val := idx, val
go func() {
fmt.Println(val.s)
fmt.Println("Completed index", idx)
wg.Done()
}()
}

wg.Wait()
}
20 changes: 20 additions & 0 deletions go/anonymous-race-condition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,23 @@ rules:
}(...)
...
}
- pattern-not: |
for $Y, $X := range ... {
...
$Y, $X := $Y, $X
...
go func(...){
...
<... $X.$VAR ...>
}(...)
}
- pattern-not: |
for $Y, $X := range ... {
...
$Y, $X := $Y, $X
...
go func(...){
...
<... $Y.$VAR ...>
}(...)
}

0 comments on commit 16db752

Please sign in to comment.