Page 1 of 1
Is the server single threaded?
Posted: 07 August 2020, 07:42
by vinayakr
Is the game server single threaded? I'm developing Tichu and a player can play a bomb at any time out of turn. Do I need to have Mutex's in place so that a player can't play normally while this player is playing out of turn or is the server single threaded and will finish any action it is currently on?
Re: Is the server single threaded?
Posted: 07 August 2020, 09:26
by Idsky
I'm still new to the BGA framework but the javascript user interface cannot commit to any action until it has confirmed it with the PHP server side.
So if player A and player B both do something at about the same time, the server will process one of those first, and notify the other player about it, which may prevent their action from being accepted. Even after they have clicked, their action can became invalid before it can be actioned by server game logic.
Re: Is the server single threaded?
Posted: 07 August 2020, 13:26
by Draasill
Based on the "SOLO" game (where a player can put a card at any time on some conditions), I have, for "Coinche", did the same thing; I've never had any problem, even when players tried to "Coinche" just before another player confirm its bid (so, too late).
That's not a good answer, I know, just some feedback

Re: Is the server single threaded?
Posted: 08 August 2020, 13:10
by shadowphiar
I'm not an admin and I don't know the internal implementation details, but I don't think it would be safe to rely on the server operating as single thread. However mySQL does offer some higher-level controls so you shouldn't have to write mutexes directly. It is documented that BGA uses Transactions for database operations, meaning that any writes to perform in a given php call will be applied atomically - i.e. other viewers will see either all of them or none of them, and nothing in between. I believe this also means that
Locking Reads are available, if your php needs to read and update the db, adding this to the read:
will cause the second thread to wait until the first transaction has completely finished before it can even read the db.
Re: Is the server single threaded?
Posted: 15 August 2020, 03:09
by XCID
shadowphiar wrote: ↑08 August 2020, 13:10
will cause the second thread to wait until the first transaction has completely finished before it can even read the db.
THANK YOU! It seems like that fixed a big problem I had when, in a multiplayer state, two players triggered the action at the exact same time!