/** * Insert another process to the pri-parallel object at the specifed * index. The point of insertion is significant because the ordering of * process components determines the priorities. The extended network * will be executed the next time run() is invoked. * <P> * @param process the process to be inserted * @param index the index at which to insert the process */ internal void insertProcessAt(IamCSProcess process, int index) { lock (sync) { if (index >= nProcesses + 1) { throw new IndexOutOfRangeException(index + " > " + (nProcesses + 1)); } if (process != null) { /*final*/ int targetProcesses = nProcesses + 1; if (targetProcesses > processes.Length) { /*final*/ IamCSProcess[] tmp = processes; processes = new IamCSProcess[2 * targetProcesses]; Array.Copy(tmp, 0, processes, 0, index); Array.Copy(tmp, index, processes, index + 1, nProcesses - index); } else { if (index < nProcesses) { Array.Copy(processes, index, processes, index + 1, nProcesses - index); } } processes[index] = process; nProcesses = targetProcesses; processesChanged = true; } } }
/** * This is invoked by a <I>server</I> when it commits to accepting a CALL * from a <I>client</I>. The parameter supplied must be a reference to this <I>server</I> * - see the <A HREF="One2OneCallChannel.html#Accept">example</A> from {@link One2OneCallChannel}. * It will not complete until a CALL has been made. If the derived CALL channel has set * the {@link #selected} field in the way defined by the standard * <A HREF="One2OneCallChannel.html#One2OneFooChannel">calling sequence</A>, * the value returned by this method will indicate which method was called. * * @param server the <I>server</I> process receiving the CALL. */ public /*synchronized*/ int accept(IamCSProcess server) { this.server = server; c.read(); // ready to ACCEPT the CALL d.read(); // wait until the CALL is complete return(selected); }
protected int selected = 0; // set (optionally) by the caller /** * This is invoked by a <I>server</I> when it commits to accepting a CALL * from a <I>client</I>. The parameter supplied must be a reference to this <I>server</I> * - see the <A HREF="One2OneCallChannel.html#Accept">example</A> from {@link One2OneCallChannel}. * It will not complete until a CALL has been made. If the derived CALL channel has set * the {@link #selected} field in the way defined by the standard * <A HREF="One2OneCallChannel.html#One2OneFooChannel">calling sequence</A>, * the value returned by this method will indicate which method was called. * * @param server the <I>server</I> process receiving the CALL. */ public int accept(IamCSProcess server) { // invoked by the callee this.server = server; c.read(); // ready to ACCEPT the CALL d.read(); // wait until the CALL is complete return(selected); }
/** * Remove a process from the <TT>Sequence</TT> object. The cut-down network * will be executed the next time run() is invoked. * * @param process the process to be removed */ public /*synchronized*/ void removeProcess(IamCSProcess process) { for (int i = 0; i < nProcesses; i++) { if (processes[i] == process) { if (i < nProcesses - 1) { Array.Copy(processes, i + 1, processes, i, nProcesses - (i + 1)); } nProcesses--; processes[nProcesses] = null; return; } } }
/** * Add the process to the <TT>Sequence</TT> object. * The extended network * will be executed the next time run() is invoked. * * @param process The CSProcess to be added */ public /*synchronized*/ void addProcess(IamCSProcess process) { if (process != null) { /*final*/ int targetProcesses = nProcesses + 1; if (targetProcesses > processes.Length) { /*final*/ IamCSProcess[] tmp = processes; processes = new IamCSProcess[2 * targetProcesses]; Array.Copy(tmp, 0, processes, 0, nProcesses); } processes[nProcesses] = process; nProcesses = targetProcesses; } }
/** * Remove the process from the <TT>CSPParallel</TT> object. The cut-down network * will not be executed until the next time <TT>run()</TT> is invoked. * * @param process the IamCSProcess to be removed */ public void removeProcess(IamCSProcess process) { lock (sync) { for (int i = 0; i < nProcesses; i++) { if (processes[i] == process) { if (i < nProcesses - 1) { Array.Copy(processes, i + 1, processes, i, nProcesses - (i + 1)); } nProcesses--; processes[nProcesses] = null; processesChanged = true; return; } } } }
/** * Add the process to the <TT>CSPParallel</TT> object. The extended network * will be executed the next time <TT>run()</TT> is invoked. * * @param process the IamCSProcess to be added */ public void addProcess(IamCSProcess process) { lock (sync) { if (process != null) { /*final*/ int targetProcesses = nProcesses + 1; if (targetProcesses > processes.Length) { /*final*/ IamCSProcess[] tmp = processes; processes = new IamCSProcess[2 * targetProcesses]; Array.Copy(tmp, 0, processes, 0, nProcesses); } processes[nProcesses] = process; nProcesses = targetProcesses; processesChanged = true; } } }
static void Main(string[] args) { // synchronisation components AltingBarrier[] stable = AltingBarrier.create(10); var elfGroups = Bucket.create(4); // Santa to Vestibule Channels One2OneChannel openForBusiness = Channel.createOne2One(); One2OneChannel consultationOver = Channel.createOne2One(); //reindeer channels Any2OneChannel harness = Channel.createAny2One(); One2AnyChannel harnessed = Channel.createOne2Any(); One2AnyChannel returned = Channel.createOne2Any(); One2OneChannel[] unharness = Channel.createOne2One(9); ChannelOutputList unharnessList = new ChannelOutputList(unharness); // elf channels, including Vestibule channels Any2OneChannel needToConsult = Channel.createAny2One(); One2AnyChannel joinGroup = Channel.createOne2Any(); Any2OneChannel consult = Channel.createAny2One(); Any2OneChannel negotiating = Channel.createAny2One(); One2OneChannel[] consulting = Channel.createOne2One(10); One2OneChannel[] consulted = Channel.createOne2One(10); ChannelOutputList consultingList = new ChannelOutputList(consulting); ChannelOutputList consultedList = new ChannelOutputList(consulted); List <IamCSProcess> grottoList = new List <IamCSProcess>(); Reindeer[] herd = new Reindeer[9]; for (int i = 0; i < 9; i++) { herd[i] = new Reindeer(number: i, stable: stable[i], harness: harness.Out(), harnessed: harnessed.In(), returned: returned.In(), unharness: unharness[i].In(), holidayTime: 15000 ); grottoList.Add(herd[i]); } Elf[] elves = new Elf[9]; IamCSProcess[] elvesNetwork = new IamCSProcess[8]; for (int i = 0; i < 9; i++) { elves[i] = new Elf(number: i, groups: elfGroups, needToConsult: needToConsult.Out(), joinGroup: joinGroup.In(), consult: consult.Out(), consulting: consulting[i].In(), negotiating: negotiating.Out(), consulted: consulted[i].In(), workingTime: 1000 ); grottoList.Add(elves[i]); } Santa santa = new Santa(openForBusiness: openForBusiness.Out(), consultationOver: consultationOver.Out(), harness: harness.In(), harnessed: harnessed.Out(), returned: returned.Out(), unharnessList: unharnessList, stable: stable[9], consult: consult.In(), consulting: consultingList, negotiating: negotiating.In(), consulted: consultedList, deliveryTime: 1000, consultationTime: 1000 ); Vestibule vestibule = new Vestibule(groups: elfGroups, needToConsult: needToConsult.In(), joinGroup: joinGroup.Out(), openForBusiness: openForBusiness.In(), consultationOver: consultationOver.In() ); grottoList.Add(santa); grottoList.Add(vestibule); IamCSProcess[] grotto = grottoList.ToArray(); new CSPParallel(grotto).run(); }
public int accept(IamCSProcess server) { throw new NotImplementedException(); }
/** * @param <TT>process</TT> the {@link IamCSProcess} to be executed by this ProcessManager */ public ProcessManager(IamCSProcess process) { this.process = process; thread = new ParThread(this.process, new CSPBarrier()); }
/** * Insert another process to the pri-parallel object at the specifed * index. The point of insertion is significant because the ordering of * process components determines the priorities. The extended network * will be executed the next time run() is invoked. * <P> * @param process the process to be inserted * @param index the index at which to insert the process */ public void insertProcessAt(IamCSProcess process, int index) { base.insertProcessAt(process, index); }