-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Concurrency fixes #211
Comments
add mutex to holes, players, junk maps |
I had a poke into this this morning 😋
I don't think this is enough - while this is helpful for protecting the maps and the pointers they contain, it doesn't protect against modifications to individual structs effectively, because modifying just one struct will block access to the entire map. I think you can use // Hole contains the data for a hole's position and size
type Hole struct {
// ... everything private
m sync.RWMutex
}
// Update reduces this holes life and increases radius if max not reached
func (h *Hole) Update() {
h.M.Lock()
h.life--
if h.Life < h.StartingLife-HoleInfancy {
h.isAlive = true
}
if h.Radius < MaxHoleRadius*1.2 {
h.radius += 0.02
h.gravityRadius += 0.03
}
h.m.Unlock()
} this means stuff in |
I realized this earlier today too! I'm going to try creating my own concurrentMap type which will contain the original map of key -> value as well as an additional map of key -> lock so that each struct has it's own ReadWrite lock. Obviously this will increase the space used but I think that's doable. Let me know if you see any issues with this approach! @bobheadxi |
I think that might work 👍 |
Instead of another map, can a If you wanna build your own map type, check out |
This is the approach I suggested, but either way works I think, so long as access is enforced through the custom map. This way you could have functionality similar to |
Riiight. Thank you for your input :) @SeeratSek if your custom type can support both maps and slices, that'd be reaaaally dope |
update: for now, we will be creating a concurrentmap type as well as a concurrentslice type. Hopefully will be able to eventually support both at once |
Add synchronization logic between game and arena
Well-known data races exist, but strangely, none of them has led to any catastrophic behaviour (as far as we can tell). We should be proactive and fix all possible data races before one of them breaks something. A good start would be to update our slice/map to be concurrency-safe, then considering what functions need additional synchronization.
The text was updated successfully, but these errors were encountered: