i still try to understand how multithreading works on server side.
A far as i understand each player has a 'event pipeline' with dedicated thread. And, all events from this player are put to the queue, for example, ->[Disconnected, Message, Message, Connected]-> (FIFO), and, relevant room callbacks are called sequentially for this player. So, no next event will be fired for player if currently some event is processing for this player. Am i right?
Question is: I know that two GotMessage callbacks may be called for two different players simultaneously, but is it possible that two GotMessage callbacks will be called for one player simultaneously? For example, on server side i acquire lock, and block other threads, during that player will send two messages, so server will receive these messages and what would be the result? Server will call GotMessage for first message, in this function we'll try to acquire lock but thread will be blocked (because lock was acquired earlier), and simultaneously call another GotMessage for second message, and thread will be blocked too. After some time, lock will be released, and scheduler may decide to continue GotMessage witch was called for second message, so, messages will be processed out of order. Is that possible?
Brief code example:
- Code: Select all
private object m_lock = new object();
private void Test()
{
lock(m_lock)
{
// Do something
}
}
public override void GameStarted()
{
Test();
}
public override void GotMessage(Player _player, Message _message)
{
Test();
}