Is the server single threaded?

Game development with Board Game Arena Studio
Post Reply
User avatar
vinayakr
Posts: 4
Joined: 13 April 2020, 02:12

Is the server single threaded?

Post 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?
User avatar
Idsky
Posts: 132
Joined: 16 April 2020, 16:49

Re: Is the server single threaded?

Post 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.
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Re: Is the server single threaded?

Post 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 😅
User avatar
shadowphiar
Posts: 124
Joined: 01 January 2017, 16:07

Re: Is the server single threaded?

Post 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:

Code: Select all

SELECT ...  FOR UPDATE
will cause the second thread to wait until the first transaction has completely finished before it can even read the db.
User avatar
XCID
Posts: 78
Joined: 26 March 2020, 01:45

Re: Is the server single threaded?

Post by XCID »

shadowphiar wrote: 08 August 2020, 13:10

Code: Select all

SELECT ...  FOR UPDATE
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!
Post Reply

Return to “Developers”