demo-realtime-unity and threading

Options
Barry
edited February 2011 in DotNet
Question: Why does Game.cs in demo-realtime-unity make calls to lock()?

Details:

In the demo code which ships with the Unity3D SDK (specifically, Photon-Unity3D_v6-1-0_SD.zip), there is a file called Game.cs. That file defines a class called Game that has a number of methods which call various LitePeer methods (e.g., peer.OpJoin(), peer.Connect()).

In each of the cases, the method locks the Game instance before processing the code which will call the Lite Peer method, e.g.:

//makes sure join does not clash with other peer-related activities (by locking it)
public void Join()
{
lock (this)
{
this.peer.OpJoin(this.gameID, null, null, false);
}
}

Despite the associated comment, I'm not sure why this locking is necessary. The Unity script (usePhoton.cs) which makes calls into it doesn't create any new threads and, to my understanding, Unity itself is single-threaded as far as its execution of scripts.

So: are these calls to lock() necessary and, if so, why?

Thanks,
Barry

Comments

  • Boris
    Options
    They are not necessary.
    Tobias told me that he uses the same code base for another demo (and that this other demo would require the locks) - I'm sure he will post further details soon.