public WaitForMany(int n) { wait = joiner.NewSyncMethod(Wait); signal = joiner.NewAsyncMethod(Signal); (wait & n * signal).Do(() => { }); }
public AsyncBuffer() { #region initialization joiner = new Joiner(); get = joiner.NewSyncMethod <T>(Get); put = joiner.NewAsyncMethod <T>(Put); #endregion (get & put).Do((T t) => { Log.Trace("Match 'get & put': passing " + t + " from Put to Get"); return(t); }); }
public BoundedSyncBuffer(int size) { #region initialization joiner = new Joiner(); put = joiner.NewSyncMethod <T>(Put); get = joiner.NewSyncMethod <T>(Get); emptySlot = joiner.NewAsyncMethod(EmptySlot); fullSlot = joiner.NewAsyncMethod <T>(FullSlot); #endregion (put & emptySlot).Do((T t) => { Log.Trace("Match 'put & emptySlot': passing " + t + " from Put to EmptySlot"); FullSlot(t); }); (get & fullSlot).Do((T t) => { Log.Trace("Match 'get & fullSlot': passing " + t + " from FullSlot to Get"); EmptySlot(); return(t); }); size.Times(() => EmptySlot()); }
public AsyncBuffer() { joiner = new Joiner(); // initialize and register the Method instances // with the Jointer get = joiner.NewSyncMethod <T>(Get); put = joiner.NewAsyncMethod <T>(Put); // combine the Methods to define patterns/chords the code in // the lambda will be invoked whenever there is a match. // In this case there will be a match whenever // both Get and Put have been invoked (get & put).Do((T t) => { Log.Trace("Match 'get & put': passing " + t + " from Put to Get"); return(t); }); }
public FairReaderWriterLock() { #region initialization joiner = new Joiner(); getWriter = joiner.NewSyncMethod(GetWriter); releaseWriter = joiner.NewSyncMethod(ReleaseWriter); getReader = joiner.NewSyncMethod(GetReader); releaseReader = joiner.NewSyncMethod(ReleaseReader); idle = joiner.NewAsyncMethod(Idle); readers = joiner.NewAsyncMethod <int>(Readers); fewerReaders = joiner.NewAsyncMethod <int>(FewerReaders); zeroReader = joiner.NewSyncMethod(ZeroReader); idleWriter = joiner.NewAsyncMethod(IdleWriter); writer = joiner.NewAsyncMethod(Writer); #endregion (getWriter & idle).Do(() => { Writer(); }); (releaseWriter & writer).Do(() => { Idle(); }); (getReader & idle).Do(() => { Readers(1); }); (getReader & readers).Do((int n) => { Readers(n + 1); }); (releaseReader & readers).Do((int n) => { if (n == 1) { Idle(); } else { Readers(n - 1); } }); (getWriter & readers).Do((int n) => { FewerReaders(n); ZeroReader(); }); (zeroReader & idleWriter).Do(() => { Writer(); }); (releaseReader & fewerReaders).Do((int n) => { if (n == 1) { IdleWriter(); } else { FewerReaders(n - 1); } }); //start state Idle(); }
public ReaderWriterLock() { #region initialization joiner = new Joiner(); getWriter = joiner.NewSyncMethod(GetWriter); releaseWriter = joiner.NewSyncMethod(ReleaseWriter); getReader = joiner.NewSyncMethod(GetReader); releaseReader = joiner.NewSyncMethod(ReleaseReader); idle = joiner.NewAsyncMethod(Idle); readers = joiner.NewAsyncMethod <int>(Readers); writer = joiner.NewAsyncMethod(Writer); #endregion (getWriter & idle).Do(() => { Writer(); }); (releaseWriter & readers).Do((int n) => { Readers(n); throw new Exception("Cannot release writer lock if not taken"); }); // getReader & idle => Readers(1); (releaseReader & idle).Do(() => { Idle(); throw new Exception("Cannot release reader lock if not taken"); }); //need a async Writer state, otherwise a call to releaseWriter will generate an idle... // releaseWriter & writer => Idle() (releaseWriter & writer).Do(() => { Log.Trace("Match 'releaseWriter & writer': idle"); Idle(); }); // getReader & idle => Readers(1); (getReader & idle).Do(() => { Log.Trace("Match 'getReader & idle': " + 1 + " readers"); Readers(1); }); // getReader & readers(n) => Readers(n+1); (getReader & readers).Do((int n) => { Log.Trace("Match 'getReader & readers': " + (n + 1) + " readers"); Readers(n + 1); }); // releaseReader & readers(n) => Readers(n-1); (releaseReader & readers).Do((int n) => { if (n == 1) { Log.Trace("Match 'releaseReader & readers': " + 0 + " readers"); Idle(); } else { Log.Trace("Match 'releaseReader & readers': " + (n - 1) + " readers"); Readers(n - 1); } }); //start state Idle(); }