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); } } }
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)); } } }
public void PutInformation(InformationLine newLine, int id) { lock (lockerPut) { Console.WriteLine("Gija " + id + ": Vykdau PutInformation()"); output.PutAndSort(newLine); Monitor.PulseAll(lockerPut); } }
public InformationLine GetInformation() { if (left == 0) { return(null); } InformationLine get = listOfInformation[left-- - 1]; listOfTakenInformation.Add(get); return(get); }
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)); }