示例#1
0
 public bool GetInformation(ref InformationLine threadInfo, int id)
 {
     if (over && empty)
     {
         threadInfo = null;
         return(false);
     }
     if (empty == true)
     {
         return(true);
     }
     lock (lockerGet)
     {
         if (full)
         {
             full = false;
         }
         if (used.Count == 0)
         {
             empty = true;
             Console.WriteLine("Gija " + id + ": Vykdau GetInformation(), bet tuscias masyvas");
             return(true);
         }
         else
         {
             Console.WriteLine("Gija " + id + ": Vykdau GetInformation()");
             int index = used.First();
             used.Remove(index);
             threadInfo = informationArray[index];
             informationArray[index] = null;
             Monitor.PulseAll(lockerGet);
             return(false);
         }
     }
 }
示例#2
0
 public CustomThread(NewMonitor monitor, int sort)
 {
     id           = numberOfThreads++;
     currentInfo  = null;
     this.monitor = monitor;
     sortBy       = sort;
 }
        private bool MoveToNewField(InformationLine info, int current)
        {
            if (Size == current)
            {
                output[current] = info;
                Size++;
                return(true);
            }
            if (ascending)
            {
                switch (info.CompareTo(output[current]))
                {
                case 1:
                    InformationLine temp = new InformationLine(output[current].word, output[current].zNumber, output[current].rNumber);
                    output[current] = info;
                    return(MoveToNewField(temp, ++current));

                default:
                    return(MoveToNewField(info, ++current));
                }
            }
            else
            {
                switch (info.CompareTo(output[current]))
                {
                case -1:
                    InformationLine temp = new InformationLine(output[current].word, output[current].zNumber, output[current].rNumber);
                    output[current] = info;
                    return(MoveToNewField(temp, ++current));

                default:
                    return(MoveToNewField(info, ++current));
                }
            }
        }
示例#4
0
 public void PutInformation(InformationLine newLine, int id)
 {
     lock (lockerPut)
     {
         Console.WriteLine("Gija " + id + ": Vykdau PutInformation()");
         output.PutAndSort(newLine);
         Monitor.PulseAll(lockerPut);
     }
 }
示例#5
0
        public InformationLine GetInformation()
        {
            if (left == 0)
            {
                return(null);
            }
            InformationLine get = listOfInformation[left-- - 1];

            listOfTakenInformation.Add(get);
            return(get);
        }
示例#6
0
 public bool MainIsAddingInformation()
 {
     lock (lockerGet)
     {
         if (full)
         {
             Console.WriteLine("Pagrindine gija: Pilnas masyvas");
             Monitor.PulseAll(lockerGet);
             return(true);
         }
         int index = FindFreeSpaceIndex();
         if (index < 0)
         {
             Console.WriteLine("Pagrindine gija: Nera vietos masyve");
             full = true;
             Monitor.PulseAll(lockerGet);
             return(true);
         }
         else
         {
             Console.WriteLine("Pagrindine gija: įdedu informaciją");
             InformationLine newInfo = document.GetInformation();
             if (newInfo == null)
             {
                 Console.WriteLine("Pagrindine gija: Pasibaige, nes gautas null");
                 over = true;
                 Monitor.PulseAll(lockerGet);
                 return(false);
             }
             else
             {
                 if (empty)
                 {
                     empty = false;
                 }
                 used.Add(index);
                 informationArray[index] = newInfo;
                 Monitor.PulseAll(lockerGet);
                 return(true);
             }
         }
     }
 }
 public bool PutAndSort(InformationLine info)
 {
     return(MoveToNewField(info, 0));
 }