is it safe to Enqueue() from one fiber to another?

Options
mindlube
edited July 2012 in Photon Server
from another thread which has died:
dreamora wrote:
If you keep a single fiber per user / room / encapsulated environment and do the communication between them through message / actionqueue then photon will handle all the concurrency for you
OK just a sanity check (for myself). In my non-room-based custom server app, I have my peer subclass CD3Peer, and my ApplicationBase subclass, App. The App has pool fiber named ExecutionFiber.
In my peer I've simply got the constructor and 2 overrides. I know it's simplistic and not massively scalable but that's OK :
   public CD3Peer(IRpcProtocol rpcProtocol, IPhotonPeer nativePeer)
			: base(rpcProtocol, nativePeer)
        {
        }
        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {
			App.executionFiber.Enqueue( () => App.PeerDisconnected(this) );
		}	
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {			
			App.executionFiber.Enqueue( () => App.ExecuteOperation( this, operationRequest, sendParameters ) );
        }
This use of Enqueue() from peer fiber to App fiber is "thread-safe" , correct? Because it's pretty much *identical* to what is going in Lite:
LitePeer -> HandleGameOperation() -> Room.EnqueueOperation() -> this.ExcecutionFiber.Enqueue( () => ... )
I thought I read otherwise, somewhere in the forums, so just checking.
thanks

Comments

  • dreamora
    Options
    enqueue is how you 'execute' something on other fibers actually. Anything else wouldn't be threadsafe, but enqueue ensures that the code is executed by the fiber itself hence no cross thread access
  • ok thanks! thanks to Photon for handling threading so nicely :)