Skip to content

Commit

Permalink
Made world.NewId() a threadsafe operation
Browse files Browse the repository at this point in the history
  • Loading branch information
unitoftime committed Aug 23, 2023
1 parent 616eb3c commit 6199f4d
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions world.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ func (w *World) NewId() Id {
for {
val := w.idCounter.Load()
if w.idCounter.CompareAndSwap(val, val+1) {
ret := (Id(val) % (w.maxId-w.minId)) + w.minId
println(ret)
return ret
return (Id(val) % (w.maxId-w.minId)) + w.minId
}
}

Expand Down

0 comments on commit 6199f4d

Please sign in to comment.