GameStorage global mutex

I’m making a “grand” game, for lack of a better term. It’s utilizing game storage to kind of make a community level game that can last weeks, rather than just a single session.

There are race condition problems involving starting a new round, since that has to be handled by the server, of which there can be many.

I’m wondering if it’s feasible to ask for an overarching schedule function.

For example, imagine 10 servers all running the same game, and we meet the victory condition for a team. All 10 servers would run GameStorage.UpdateCounter("round", 1)

Even with checks against the current round, it’s still a race condition.

The solution I’m imagining is basically a global mutex.

GameStorage.Mutex("new-round", function()
  GameStorage.GetCounter("round", function(round)
    if round == someLocalCurrentRound then
      GameStorage.UpdateCounter("round", 1)

So server 1 runs the function, and locks the new-round mutex. Server 2 runs the function, waits for the lock to release.
Server 1 finishes and releases the lock.

Server 2 is now allowed to run the function, but since the round is now incremented, it’s a no-op on the counter.

1 Like