Пример #1
0
 /// <summary>
 /// Philosopher
 /// 
 /// Accepts the philosophers number, Forks and the number of philosophers to eat
 /// </summary>
 /// <param name="PhilosopherNumber"></param>
 /// <param name="Forks"></param>
 /// <param name="Footman"></param>
 public Philosopher(int PhilosopherNumber, List<Fork> Forks, Semaphore Footman)
 {
     this.PhilosopherNumber = PhilosopherNumber;
     this.Footman = Footman;
     RandomNumberGenerator = new Random();
     this.Forks = Forks;
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mark.Utilities.MAC.Barrier"/> class.
 /// 
 /// This is the constructor for the Barrier class, This accepts a uLong as the limit to the barrier
 /// Please take note this will be the limit of the Threads that you want to go through at a time.
 /// </summary>
 /// <param name="Limit">Limit.</param>
 public Barrier(ulong Limit)
 {
     Count = 0;
     this.Limit = Limit;
     BarrierLock = new object ();
     Turnstyle = new Semaphore (Limit);
     Turnstyle2 = new Semaphore (0);
 }
Пример #3
0
 /// <summary>
 /// Bathroom
 /// 
 /// Setting up the conditions of the bathroom and the solution of the Starvation problem
 /// </summary>
 public Bathroom()
 {
     BathroomSemaphore = new Semaphore (1);
     MLightSwitch = new Lightswitch (BathroomSemaphore);
     FLightSwitch = new Lightswitch (BathroomSemaphore);
     QueueTS = new Semaphore (1);
     PopCounter = new Semaphore (3);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Mark.Utilities.MAC.ReaderWriter"/> class.
 /// 
 /// This Initializes the Reader Writer. All this will do is Initialize all of the global variables for the class to work.
 /// </summary>
 public ReaderWriter()
 {
     ReaderWriterLockSemaphore = new Semaphore (1);
     ReaderWriterLockLightswitch = new Lightswitch (ReaderWriterLockSemaphore);
     ReaderBlock = new Semaphore (1);
     WriteBlock = new Semaphore (1);
     NumberOfReaders = 0;
     ReaderWriterLock = new object ();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ClassicConcurrencyProblems.AgentForDining"/> class.
 /// 
 /// Initialises all of the variables used to make this possible
 /// </summary>
 /// <param name="NumberOfServ">Number of serv.</param>
 public AgentForDining(ulong NumberOfServ,bool IsTimed, int Time)
 {
     InformCook = new Semaphore (0);
     FullPot = new Semaphore (0);
     Pot = NumberOfServ;
     Max = NumberOfServ;
     Savlock = new Object ();
     IsTimedToEnd = IsTimed;
     TimeToFinish = Time;
     RandomNumberGenerator = new Random ();
     stopwatch = new Stopwatch ();
     stopwatch.Start();
 }
        public void TestStart()
        {
            semaphore = new Semaphore(0);
            for (int i = 0; i < 10; i++)
            {
                Thread aquireTask = new Thread(AquireTokenTest);

                aquireTask.Start ();

                Thread.Sleep (50);
            }
            Thread releaseTask = new Thread(ReleaseTokenTest);
            releaseTask.Start ();
        }
 /// <summary>
 /// CigaretteSmokersProblemCode Construction
 /// 
 /// Set up the programs main semaphores and components
 /// </summary>
 /// <param name="IsTimed"></param>
 /// <param name="Time"></param>
 public CigaretteSmokersProblemCode(bool IsTimed,int Time)
 {
     Tobacco = new Semaphore(0);
     Paper = new Semaphore(0);
     Match = new Semaphore(0);
     TobaccoSem = new Semaphore(0);
     PaperSem = new Semaphore(0);
     MatchSem = new Semaphore(0);
     stopwatch = new Stopwatch ();
     stopwatch.Start();
     AgentSem = new Semaphore(1);
     AgentLock = new object();
     IsTobacco = false;
     IsPaper = false;
     IsMatch = false;
     IsItTimed = IsTimed;
     TimeToEnd = Time;
     RandomNumberGenerator = new Random();
 }
        public void TestStart()
        {
            semaphore = new Semaphore(0);
            LightswitchTest = new Lightswitch (semaphore);

            Thread releaseToken = new Thread(ReleaseToken);
            Thread releaseTask = new Thread(AquireTokenLightSwitch);
            Thread releaseTask1 = new Thread(AquireTokenLightSwitch);
            Thread releaseTask2 = new Thread(AquireTokenSemaPhore);
            Thread releaseTask3 = new Thread(AquireTokenSemaPhore);
            Thread releaseTask4 = new Thread(AquireTokenLightSwitch2);
            Thread releaseTask5 = new Thread(AquireTokenLightSwitch2);
            releaseToken.Start ();
            releaseTask.Start();
            releaseTask1.Start ();
            releaseTask2.Start();
            releaseTask3.Start();
            releaseTask4.Start();
            releaseTask5.Start();
        }
        public void TestStart()
        {
            semaphore = new Semaphore(0);

            TestOne();

            Thread.Sleep(8000);

            Thread aquireTask1 = new Thread(() => ReleaseToken(3300));
            Thread aquireTask2 = new Thread(() => ReleaseToken(3300));
            aquireTask1.Start();
            aquireTask2.Start();
            Thread acquireTask = new Thread(() => AquireToken(3600));
            acquireTask.Name = "\t\t Thread One - ";
            acquireTask.Start();

            Thread acquireTask1 = new Thread(() => AquireToken(3400));
            acquireTask1.Name = "\t\t\t Thread Two - ";
            acquireTask1.Start();

            Thread acquireTask2 = new Thread(() => AquireToken(3000));
            acquireTask2.Name = "\t Expected Fail Thread - ";
            acquireTask2.Start();
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mark.Utilities.MAC.Lightswitch"/> class.
 /// 
 /// This allows the creation of the Lightswitch, this accepts a Semaphore as a paramater and only allows this to be passed in
 /// this is detrement to what you want to do, make sure you pick the right semaphore to pass in. 
 /// </summary>
 /// <param name="LightswitchSemaphore">Lightswitch semaphore.</param>
 public Lightswitch(Semaphore LightswitchSemaphore)
 {
     ThreadCount = 0;
     this.LightswitchSemaphore = LightswitchSemaphore;
     LightswitchLock = new object ();
 }
Пример #11
0
 /// <summary>
 /// Fork
 /// 
 /// Construction of a fork with a semaphore. 
 /// This is to signal if it is in use or not
 /// </summary>
 /// <param name="ForkInSemaphore"></param>
 public Fork(Semaphore ForkInSemaphore)
 {
     this.ForkInSemaphore = ForkInSemaphore;
 }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mark.Utilities.MAC.Latch"/> class.
 /// 
 /// This allows the creation of the Latch and the semaphore that is within the latch, 
 /// The semaphore will take a argument of 0, this will allow to the open door method to be effective.
 /// </summary>
 public Latch()
 {
     LatchSemaphore = new Semaphore (0);
 }