예제 #1
0
        /** ***********Methods from AltingChannelInput************************* */

        /**
         * Reads an <TT>Object</TT> from the channel.
         *
         * @return the object read from the channel.
         */
        public Object read()
        {
            /*synchronized*/
            lock (rwMonitor)
            {
                if (empty)
                {
                    empty = false;
                    try
                    {
                        Monitor.Wait(rwMonitor);
                        while (!empty)
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.One2OneChannelRead);
                            }
                            Monitor.Wait(rwMonitor);
                        }
                    }
                    catch (/*InterruptedException*/ ThreadInterruptedException e)
                    {
                        throw new ProcessInterruptedException("*** Thrown from One2OneChannel.read ()\n"
                                                              + e.ToString());
                    }
                }
                else
                {
                    empty = true;
                }
                spuriousWakeUp = false;
                Monitor.Pulse(rwMonitor);
                return(hold);
            }
        }
        public int startRead()
        {
            lock (rwMonitor) {
                if (data.getState() == ChannelDataStoreState.EMPTY)
                {
                    try
                    {
                        Monitor.Wait(rwMonitor);
                        while (data.getState() == ChannelDataStoreState.EMPTY)
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.One2OneChannelXRead);
                            }

                            Monitor.Wait(rwMonitor);
                        }
                    }
                    catch (ThreadInterruptedException�e)
                    {
                        throw new ProcessInterruptedException(
                                  "*** Thrown from One2OneChannel.read (int)\n" + e.ToString()
                                  );
                    }
                }

                return(data.startGet());
            }
        }
        public int startRead()
        {
            lock (rwMonitor) {
                if (empty)
                {
                    empty = false;
                    try
                    {
                        Monitor.Wait(rwMonitor);
                        while (!empty)
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.One2OneChannelRead);
                            }

                            Monitor.Wait(rwMonitor);
                        }
                    }
                    catch (ThreadInterruptedException e)
                    {
                        throw new ProcessInterruptedException("*** Thrown from One2OneChannel.read ()\n"
                                                              + e.ToString());
                    }
                }
                else
                {
                    empty = true;
                }

                return(hold);
            }
        }
예제 #4
0
        /**
         * This process starts, engages in no events, performs no computation
         * and refuses to terminate.
         * <p>
         */
        public void run()
        {
            Object lockedObject = new Object();

            lock (lockedObject)
            {
                try
                {
                    Monitor.Wait(lockedObject);
                    while (true)
                    {
                        if (Spurious.logging)
                        {
                            SpuriousLog.record(SpuriousLog.StopRun);
                        }

                        Monitor.Wait(lockedObject);
                    }
                }
                catch (ThreadInterruptedException e)
                {
                    throw new ProcessInterruptedException("*** Thrown from Stop.run ()\n"
                                                          + e.ToString());
                }
            }
        }
예제 #5
0
        /**
         * Fall into the bucket.
         * The process doing this will be blocked until the next {@link #flush}.
         */
        public void fallInto()
        {
            lock (bucketLock)

            {
                nHolding++;
                // System.out.println ("Bucket.fallInto : " + nHolding);
                try
                {
                    int spuriousCycle = bucketCycle;
                    Monitor.Wait(bucketLock);
                    while (spuriousCycle == bucketCycle)
                    {
                        if (Spurious.logging)
                        {
                            SpuriousLog.record(SpuriousLog.BucketFallInto);
                        }
                        Monitor.Wait(bucketLock);
                    }
                }
                catch (ThreadInterruptedException e)
                {
                    throw new ProcessInterruptedException("*** Thrown from Bucket.fallInto ()\n"
                                                          + e.ToString());
                }
            }
        }
        /*************Methods from ChannelOutput*******************************/

        /**
         * Writes an <TT>Object</TT> to the channel.
         *
         * @param value the object to write to the channel.
         */
        public void write(int value)
        {
            lock (rwMonitor)
            {
                if (isPoisoned())
                {
                    throw new PoisonException(poisonStrength);
                }

                hold = value;
                if (empty)
                {
                    empty = false;
                    if (alt != null)
                    {
                        alt.schedule();
                    }
                }
                else
                {
                    empty = true;
                    Monitor.Pulse(rwMonitor);
                }

                try
                {
                    Monitor.Wait(rwMonitor);
                    while (spuriousWakeUp && !isPoisoned())
                    {
                        if (Spurious.logging)
                        {
                            SpuriousLog.record(SpuriousLog.One2OneChannelWrite);
                        }

                        Monitor.Wait(rwMonitor);
                    }

                    spuriousWakeUp = true;
                }
                catch (ThreadInterruptedException e)
                {
                    throw new ProcessInterruptedException(
                              "*** Thrown from One2OneChannel.write (Object)\n" + e.ToString());
                }

                if (done)
                {
                    done = false;
                }
                else if (isPoisoned())
                {
                    throw new PoisonException(poisonStrength);
                }
                else
                {
                    done = true;
                }
            }
        }
        /** ***********Methods from AltingChannelInput************************* */

        /**
         * Reads an <TT>Object</TT> from the channel.
         *
         * @return the object read from the channel.
         */
        public int read()
        {
            lock (rwMonitor)
            {
                if (isPoisoned())
                {
                    throw new PoisonException(poisonStrength);
                }


                if (empty)
                {
                    empty = false;
                    try
                    {
                        Monitor.Wait(rwMonitor);
                        while (!empty && !isPoisoned())
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.One2OneChannelRead);
                            }

                            Monitor.Wait(rwMonitor);
                        }
                    }
                    catch (ThreadInterruptedException e)
                    {
                        throw new ProcessInterruptedException("*** Thrown from One2OneChannel.read ()\n"
                                                              + e.ToString());
                    }
                }
                else
                {
                    empty = true;
                }

                spuriousWakeUp = false;

                if (isPoisoned())
                {
                    throw new PoisonException(poisonStrength);
                }
                else
                {
                    done = true;
                    Monitor.Pulse(rwMonitor);
                    return(hold);
                }
            }
        }
        /**
         * Writes an <TT>Object</TT> to the channel.
         *
         * @param value the object to write to the channel.
         */
        public void write(int value)
        {
            lock (rwMonitor)
            {
                //Writer always sees poison:
                if (isPoisoned())
                {
                    throw new PoisonException(poisonStrength);
                }

                data.put(value);
                if (alt != null)
                {
                    alt.schedule();
                }
                else
                {
                    Monitor.Pulse(rwMonitor);
                }

                if (data.getState() == ChannelDataStoreState.FULL)
                {
                    try
                    {
                        Monitor.Wait(rwMonitor);
                        while (data.getState() == ChannelDataStoreState.FULL && !isPoisoned())
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.One2OneChannelXWrite);
                            }

                            Monitor.Wait(rwMonitor);
                        }
                    }
                    catch (ThreadInterruptedException e)
                    {
                        throw new ProcessInterruptedException(
                                  "*** Thrown from One2OneChannel.write (Object)\n" + e.ToString()
                                  );
                    }

                    if (isPoisoned())
                    {
                        throw new PoisonException(poisonStrength);
                    }
                }
            }
        }
        /**
         * Writes an <TT>int</TT> to the channel.
         *
         * @param value the integer to write to the channel.
         */
        public void write(int value)
        {
            //Debug.WriteLine("Int write is " + value);
            // Debug.WriteLine("Int write hold is " + hold);
            lock (rwMonitor) {
                hold = value;
                if (empty)
                {
                    empty = false;
                    if (alt != null)
                    {
                        alt.schedule();
                    }
                }
                else
                {
                    empty = true;
                    Monitor.Pulse(rwMonitor);
                }

                try
                {
                    Monitor.Wait(rwMonitor);
                    while (spuriousWakeUp)
                    {
                        if (Spurious.logging)
                        {
                            SpuriousLog.record(SpuriousLog.One2OneChannelIntWrite);
                        }

                        Monitor.Wait(rwMonitor);
                    }

                    spuriousWakeUp = true;
                }
                catch (ThreadInterruptedException e)
                {
                    throw new ProcessInterruptedException(
                              "*** Thrown from One2OneChannelInt.write (int)\n" + e.ToString()
                              );
                }
            }
        }
        public int startRead()
        {
            lock (rwMonitor)
            {
                if (data.getState() == ChannelDataStoreState.EMPTY)
                {
                    //      Reader only sees poison if buffer is empty:
                    if (isPoisoned())
                    {
                        throw new PoisonException(poisonStrength);
                    }

                    try
                    {
                        Monitor.Wait(rwMonitor);
                        while (data.getState() == ChannelDataStoreState.EMPTY && !isPoisoned())
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.One2OneChannelXRead);
                            }

                            Monitor.Wait(rwMonitor);
                        }
                    }
                    catch (ThreadInterruptedException e)
                    {
                        throw new ProcessInterruptedException(
                                  "*** Thrown from One2OneChannel.read (int)\n" + e.ToString()
                                  );
                    }

                    //    Reader only sees poison if buffer is empty:
                    if (isPoisoned())
                    {
                        throw new PoisonException(poisonStrength);
                    }
                }

                return(data.startGet());
            }
        }
예제 #11
0
        /*************Methods from ChannelOutput*******************************/

        /**
         * Writes an <TT>Object</TT> to the channel.
         *
         * @param value the object to write to the channel.
         */
        public void write(Object value)
        {
            /*synchronized*/
            lock (rwMonitor)
            {
                hold = value;
                if (empty)
                {
                    empty = false;
                    if (alternative != null)
                    {
                        alternative.schedule();
                    }
                }
                else
                {
                    empty = true;
                    Monitor.Pulse(rwMonitor);
                }
                try
                {
                    Monitor.Wait(rwMonitor);
                    while (spuriousWakeUp)
                    {
                        if (Spurious.logging)
                        {
                            SpuriousLog.record(SpuriousLog.One2OneChannelWrite);
                        }
                        Monitor.Wait(rwMonitor);
                    }
                    spuriousWakeUp = true;
                }
                catch (/*InterruptedException*/ ThreadInterruptedException e)
                {
                    throw new ProcessInterruptedException(
                              "*** Thrown from One2OneChannel.write (Object)\n" + e.ToString());
                }
            }
        }
예제 #12
0
        /**
         * Synchronise the invoking process on this barrier.
         * <I>Any</I> process synchronising on this barrier will be blocked until <I>all</I>
         * processes associated with the barrier have synchronised (or resigned).
         */
        public void sync()
        {
            //Debug.WriteLine("Before locking Barrier", "KAROL");
            lock (barrierLock) {
                countDown--;
                //System.out.println ("CSPBarrier.sync : " + nEnrolled + ", " + countDown);
                if (countDown > 0)
                {
                    try
                    {
                        Boolean spuriousCycle = evenOddCycle;
                        Monitor.Wait(barrierLock);
                        while (spuriousCycle == evenOddCycle)
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.BarrierSync);
                            }
                            Monitor.Wait(barrierLock);
                        }
                    }
                    catch (ThreadInterruptedException e)
                    {
                        throw new ProcessInterruptedException(
                                  "*** Thrown from CSPBarrier.sync ()\n" + e.ToString()
                                  );
                    }
                }
                else
                {
                    countDown    = nEnrolled;
                    evenOddCycle = !evenOddCycle;         // to detect spurious wakeups  :(

                    //Debug.WriteLine("CSPBarrier.sync : " + nEnrolled + ", " + countDown, "KAROL");
                    Monitor.PulseAll(barrierLock);
                }
            }
        }
/**
 * Writes an <TT>int</TT> to the channel.
 *
 * @param value the integer to write to the channel.
 */
        public void write(int value)
        {
            lock (rwMonitor) {
                data.put(value);
                if (alt != null)
                {
                    alt.schedule();
                }
                else
                {
                    Monitor.Pulse(rwMonitor);
                }

                if (data.getState() == ChannelDataStoreState.FULL)
                {
                    try
                    {
                        Monitor.Wait(rwMonitor);
                        while (data.getState() == ChannelDataStoreState.FULL)
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.One2OneChannelIntXWrite);
                            }

                            Monitor.Wait(rwMonitor);
                        }
                    }
                    catch (ThreadInterruptedException�e)
                    {
                        throw new ProcessInterruptedException(
                                  "*** Thrown from One2OneChannelInt.write (int)\n" + e.ToString()
                                  );
                    }
                }
            }
        }
예제 #14
0
        /**********************************************************************/

        /**
         * Reads an <TT>int</TT> from the channel.
         *
         * @return the integer read from the channel.
         */
        public int read()
        {
            //Debug.WriteLine("Int read hold is " + hold);
            lock (rwMonitor) {
                if (empty)
                {
                    empty = false;
                    try
                    {
                        Monitor.Wait(rwMonitor);
                        while (!empty)
                        {
                            if (Spurious.logging)
                            {
                                SpuriousLog.record(SpuriousLog.One2OneChannelIntRead);
                            }

                            Monitor.Wait(rwMonitor);
                        }
                    }
                    catch (ThreadInterruptedException e)
                    {
                        throw new ProcessInterruptedException(
                                  "*** Thrown from One2OneChannelInt.read ()\n" + e.ToString()
                                  );
                    }
                }
                else
                {
                    empty = true;
                }

                spuriousWakeUp = false;
                Monitor.Pulse(rwMonitor);
                return(hold);
            }
        }