Advertisement
PomozMi

semafor

Dec 15th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. // https://github.com/SOP2014/sop
  2. // https://github.com/HueHueHue/HueOS
  3. // https://subversion.assembla.com/svn/sopy/SystemOperacyjny/
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace Warstwa1
  11. {
  12.     public class Semaphore
  13.     {
  14.  
  15.         public IList<PCB> ProcesList = new List<PCB>(); // lista procesów
  16.         public int value;
  17.  
  18.  
  19.  
  20.         Semaphore() { }
  21.         //        Semaphore(jakie potrzebujecie??){}
  22.         public Semaphore(int value)
  23.         {
  24.             if (value < 0)
  25.                 throw new ArgumentOutOfRangeException(" Początkowa wartość semafora musi być nieujemna! ");
  26.             this.value = value;
  27.         }
  28.  
  29.         public void OperationP()  //P — opuszczanie semafora (hol. proberen),
  30.         {
  31.             value--;
  32.             if (value < 0)
  33.             {
  34.                 Zawiadowca.RUNNING.BLOCKED = true;// czeka na sygnaał (operacja V) , więc nie może być chilowo wykonywany
  35.                 ProcesList.Add(Zawiadowca.RUNNING);// do listy dodaje obiekt PCB
  36.                 Warstwa5.Program.MainForm.addToList(" Operacja P. Dodaję proces do listy oczekujących.\n Wartość semafora: " + value);
  37.             }
  38.         }
  39.  
  40.  
  41.         //  Operacja V
  42.         public void OperationV()// V — podnoszenie semafora (hol. verhogen).
  43.         {
  44.             value++;
  45.  
  46.             if (value <= 0)
  47.             {
  48.                 Warstwa5.Program.MainForm.addToList(" Operacja V...");
  49.  
  50.                 if (ProcesList != null)
  51.                 {
  52.                     PCB tmp = ProcesList.First();
  53.                     tmp.BLOCKED = false;
  54.                     ProcesList.Remove(ProcesList.First()); // może być?
  55.                     Warstwa5.Program.MainForm.addToList(" Odpalam proces, który czekał. Wartość semafora: " + value);
  56.                 }
  57.                 else
  58.                 {
  59.                     Warstwa5.Program.MainForm.addToList(" Żodyn nie czeka. Wartość semafora: " + value);
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement