Beispiel #1
0
 def start(self):
     for i in range(0, 4):
         if (i == 0 or i == 1):
             self.resource_list[i] = RCB(id=i, numUnits=1)
         if (i == 2):
             self.resource_list[i] = RCB(id=i, numUnits=2)
         if (i == 3):
             self.resource_list[i] = RCB(id=i, numUnits=3)
Beispiel #2
0
 def __init__(self):
     r1 = RCB("R1", 1)
     r2 = RCB("R2", 2)
     r3 = RCB("R3", 3)
     r4 = RCB("R4", 4)
     self._resource_list = list()
     self._resource_list.append(r1)
     self._resource_list.append(r2)
     self._resource_list.append(r3)
     self._resource_list.append(r4)
Beispiel #3
0
    def request(self,r:"resource type", k:"number of units requested"):
        #print("req called {} {}".format(r,k))
        if r < 0 or r > 3:
            print("-1", end=' ')
            return False

        req_RCB = self._RCB_list[r]
        available_units = req_RCB.state
        running_PCB = self._get_running_proc()

        # error check here
        if not self._req_error_check(running_PCB,r,k):
            print("-1", end=' ')
            return False

        if available_units >= k:
            req_RCB.state = available_units - k
            running_PCB.append_resource(RCB(r,k))
            # print("resource {} allocated".format(r))

        else:
            self.ready_list.remove(running_PCB)
            self._set_running_proc(self.ready_list.get_all()[0])
            req_RCB.waitlist.append((running_PCB,k))
            # print("process {} blocked".format(running_PCB.num))
            self.scheduler()

        return
Beispiel #4
0
    def init(self) -> int:
        print("\n")
        self._PCBs = [None for _ in range(Manager._MAX_PCBs)]
        self._RCBs = [RCB() for _ in range(Manager._MAX_RCPs)]
        self._RL = [SLL() for _ in range(Manager._PRIORITY_LEVELS)]
        self._running_process = 0
        self._number_of_processes = 1

        self._PCBs[0] = PCB()
        self._RL[0].push(0)

        return self.scheduler()
Beispiel #5
0
    def release(self,r:"resource type",k:"number of units",op:"replace running proc if not None"= None):
        #print("rel called {} {}".format(r,k))

        running_proc = self._get_running_proc() if op is None else op

        if not self._rel_error_check(running_proc, r, k):
            print("-1", end='')
            return False

        units_freed = running_proc.remove_resource(r,k)
        if units_freed == False: return False





        # add freed units back to resource
        resource = self._RCB_list[r] # THIS RESOURCE IS THE MANAGER RESOURCE
        resource.state += units_freed
        #print("resource {} released".format(r))


        # if item on wait list can be unblocked,
        # unblock it by adding to ready list,
        #      adding resource to process list
        #      and removing it from wait list
        if resource.waitlist != []:
            for item in resource.waitlist.copy():
                available_units = resource.state
                process, units_requested = item[0], item[1]
                if available_units >= units_requested:
                    self.ready_list.append(process)
                    process.append_resource(RCB(r,units_requested))
                    resource.state -= units_requested
                    resource.waitlist.remove(item)
        self.scheduler()
Beispiel #6
0
 def __init__(self):
     # do not modify PCB or RCB list
     self._PCB_list = PCB_List(DEFAULT_PCBL_SIZE)
     self._RCB_list = [RCB(0,1),RCB(1,1),RCB(2,2),RCB(3,3)]
     self.ready_list = ReadyList(self._PCB_list[0])
     self.current_running_pcb = self._PCB_list[0] # returns pcb, NOT INDEX!
Beispiel #7
0
 def __init__(self):
     self.PCBArray = [PCB(None, 0, 0)] + [None] * (PCB_SIZE - 1)
     self.RCBArray = [RCB(i) for i in range(RCB_SIZE)]
     self.RL = ReadyList()
     self.RL.InsertPCB(self.PCBArray[0], 0)
     self.ErrorMode = False