Exemplo n.º 1
0
        public void ActivateWithClear()
        {
            Process p = new Process(_sim, Interruptee, true);

            p.Activate(null, 10L);
            p = new Process(_sim, Interruptor, p);
            p.Activate(null, 5L);
            _sim.Run();
        }
Exemplo n.º 2
0
        public void TransferTracked()
        {
            IResource  resource = Resource.Create(Names);
            Simulation sim      = new Simulation();
            Task       task     = new Process(sim, TransferTask, resource);

            task.Activate(null);
            sim.Run();
            Assert.AreEqual(Names.Length, resource.Free);
        }
Exemplo n.º 3
0
        public void TransferAnonymous()
        {
            IResource  resource = Resource.Create(2);
            Simulation sim      = new Simulation();
            Task       task     = new Process(sim, TransferTask, resource);

            task.Activate(null);
            sim.Run();
            Assert.AreEqual(2, resource.Free);
        }
Exemplo n.º 4
0
        public void InterruptedAcquire()
        {
            IResource  resource = Resource.Create(3);
            Simulation sim      = new Simulation();
            Process    process  = new Process(sim, AcquireOneInterrupted, resource);

            process.Activate(null);
            Assert.AreEqual(resource.Count, resource.Free);
            sim.Run();
            Assert.AreEqual(resource.Count, resource.Free);
        }
Exemplo n.º 5
0
        public void DoubleInterrupt()
        {
            Process interruptee = new Process(_sim, Interruptee, false);

            interruptee.Activate(null, 10L);
            Process p = new Process(_sim, Interruptor, interruptee);

            p.Activate(null, 5L, TaskPriority.Elevated);
            p = new Process(_sim, Interruptor, interruptee);
            p.Activate(null, 5L, TaskPriority.Elevated);
            _sim.Run();
        }
Exemplo n.º 6
0
        private IEnumerator <Task> Interruptee(Process process, object data)
        {
            Assert.IsTrue(process.Interrupted);
            if ((bool)data)
            {
                process.ClearInterrupt();
            }

            process.Activate(null, 10L);
            yield return(process);

            yield break;
        }
Exemplo n.º 7
0
        private IEnumerator <Task> TransferTask(Process p, object data)
        {
            Resource r = (Resource)data;

            yield return(r.Acquire(p));

            Assert.IsTrue(r.IsOwner(p));
            Process receiver = new Process(p.Simulation, ReceiveTransfer);

            yield return(r.Transfer(p, receiver));

            receiver.Activate(p, 10L, r);
            Assert.IsFalse(r.IsOwner(p));
            yield break;
        }
Exemplo n.º 8
0
        public void TransferUsingInterrupt()
        {
            IResource  resource = Resource.Create(1);
            Simulation sim      = new Simulation();
            Task       task1    = new Process(sim, TransferAndInterrupt, resource);

            task1.Name = "Task #1";
            Task task2 = new Process(sim, TransferAndInterrupt, resource);

            task2.Name = "Task #2";
            task1.Activate(null, 0L, task2);
            task2.Activate(null, 0L, task1);
            sim.Run();
            Assert.AreEqual(1, resource.Free);
        }