Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

Callback execution serial or parallel? #160

Closed IoannisKaragiannis closed 5 years ago

IoannisKaragiannis commented 5 years ago

Hi,

I have a question that will help me understand how the callbacks work in MLAPI.

Assume we have a networked object in a scene, and the client sends to the server msg[0] with the object's updated pose. The server receives msg[0] in the respective callback (e.g.: OnMsgReceivedFromClient()). While the callback is in the middle of processing the received msg[0], msg[1] arrives. What will happen to the callback that was processing msg[0]?

1) Will the two callbacks be scheduled on separate threads such that they will be executed in parallel? 2) Will the callback processing msg[0] be interrupted and discarded? 3) Will the callback responsible for processing msg[1] wait for the callback processing msg[0] to be completed?

Your Environment

Thanks in advance for your help.

TwoTenPvP commented 5 years ago

This is how callbacks work in C#. Execution can can only happen in parallel if you use threading. The MLAPI currently does no threading. Thus they will be executed in serial. That is, a callback can be thought of (and is often called) an anonymous function. That is a function without a name. It still shares the EXACT same properties as a method, that it has to execute its full stack before the invoke is returned.

As stated, the MLAPI is not parallel at all. Everything is sequential.

IoannisKaragiannis commented 5 years ago

Thank you very much Albin. This was a super thorough response. Now I get it. Have a nice weekend!