Skip to content

Commit

Permalink
added mutex at right places (#3678)
Browse files Browse the repository at this point in the history
* added atomic instead of mutex
  • Loading branch information
ashutosji authored Mar 8, 2024
1 parent 1c536c0 commit 1fcda51
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/load/allocation/runscenario/runscenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

pb "agones.dev/agones/pkg/allocation/go"
Expand Down Expand Up @@ -123,11 +124,12 @@ func main() {
go func() {
defer wgc.Done()
if err := allocate(client); err != noerror {
failureDtls[clientID][err]++
failureCnts[clientID]++
tmpVar := failureDtls[clientID][err]
atomic.AddUint64(&tmpVar, 1)
atomic.AddUint64(&failureCnts[clientID], 1)
}
}()
allocCnts[clientID]++
atomic.AddUint64(&allocCnts[clientID], 1)
time.Sleep(time.Duration(sc.intervalMillisecond) * time.Millisecond)
}
wgc.Wait()
Expand All @@ -141,8 +143,8 @@ func main() {
var scnAllocCnt uint64
scnErrDtls := allocErrorCodeCntMap()
for j := 0; j < sc.numOfClients; j++ {
scnAllocCnt += allocCnts[j]
scnFailureCnt += failureCnts[j]
scnAllocCnt += atomic.LoadUint64(&allocCnts[j])
scnFailureCnt += atomic.LoadUint64(&failureCnts[j])
for k, v := range failureDtls[j] {
totalFailureDtls[k] += v
scnErrDtls[k] += v
Expand Down

0 comments on commit 1fcda51

Please sign in to comment.