Example #1
0
def showSem():
    # 设置信号量
    semaphore = {'mex1': 1, 'mex2': 0, 'mex3': 0}
    # 信号量同步事件
    pcb1 = PCB(1, 5, [5, 5, 5], 10)
    pcb2 = PCB(2, 5, [5, 5, 5], 10)
    pcb3 = PCB(3, 5, [5, 5, 5], 10)

    pcb1.Semaphore = semaphore
    pcb2.Semaphore = semaphore
    pcb3.Semaphore = semaphore
    eventSem1 = {}
    eventSem1['CpuTime'] = 5
    eventSem1['task_application'] = 'S'
    eventSem1['re_mutex'] = ['mex1']  #获取 1
    eventSem1['Srequest'] = True

    eventSemR1 = {}
    eventSemR1['CpuTime'] = 2
    eventSemR1['task_application'] = 'S'
    eventSemR1['re_mutex'] = ['mex2', 'mex3']  #释放 2 3
    eventSemR1['Srequest'] = False

    eventSem2 = {}
    eventSem2['CpuTime'] = 4
    eventSem2['task_application'] = 'S'
    eventSem2['re_mutex'] = ['mex2']  # 获取 2
    eventSem2['Srequest'] = True

    eventSem3 = {}
    eventSem3['CpuTime'] = 10
    eventSem3['task_application'] = 'S'
    eventSem3['re_mutex'] = ['mex3']  # 获取 3
    eventSem3['Srequest'] = True

    pcb1.event.append(eventSem1)
    pcb1.event.append(eventSemR1)
    pcb2.event.append(eventSem2)
    pcb3.event.append(eventSem3)

    PCBList = [pcb1, pcb2, pcb3]
    iter = processManage('FIFS', PCBList)
    result = []
    try:
        for dict in next(iter):
            result.append(dict)
        yield result
    except:
        yield result  # 暂时先这样
Example #2
0
def showUnite():
    pcb1 = PCB(1, 10, [5, 5, 5], 10)
    pcb2 = PCB(2, 10, [5, 5, 5], 10)
    pcb3 = PCB(3, 10, [5, 5, 5], 10)
    pcb4 = PCB(4, 10, [5, 5, 5], 10)
    pcb5 = PCB(5, 10, [5, 5, 5], 10)

    # 进程名设置
    pcb1.name = '进程1'
    pcb2.name = '进程2'
    pcb3.name = '进程3'
    pcb4.name = '进程4'
    pcb5.name = '进程5'

    # 设置申请内存大小
    pcb1.re_mSize = 30
    pcb2.re_mSize = 20

    # 设备事件创建
    eventDeviceA1 = {}
    eventDeviceA1['CpuTime'] = 8
    eventDeviceA1['task_application'] = 'D'
    eventDeviceA1['re_Dname'] = '设备A1'
    eventDeviceA1['DeviceTime'] = 5
    eventDeviceA1['Drequest'] = True

    eventDeviceB1 = {}
    eventDeviceB1['CpuTime'] = 7
    eventDeviceB1['task_application'] = 'D'
    eventDeviceB1['re_Dname'] = '设备B1'
    eventDeviceB1['DeviceTime'] = 5
    eventDeviceB1['Drequest'] = True

    eventDeviceB11 = {}
    eventDeviceB11['CpuTime'] = 8
    eventDeviceB11['task_application'] = 'D'
    eventDeviceB11['re_Dname'] = '设备B1'
    eventDeviceB11['DeviceTime'] = 5
    eventDeviceB11['Drequest'] = True

    eventDeviceC1 = {}
    eventDeviceC1['CpuTime'] = 6
    eventDeviceC1['task_application'] = 'D'
    eventDeviceC1['re_Dname'] = '设备C1'
    eventDeviceC1['DeviceTime'] = 3
    eventDeviceC1['Drequest'] = True

    eventDeviceC12 = {}
    eventDeviceC12['CpuTime'] = 3
    eventDeviceC12['task_application'] = 'D'
    eventDeviceC12['re_Dname'] = '设备C1'
    eventDeviceC12['DeviceTime'] = 3
    eventDeviceC12['Drequest'] = True

    # 设备事件添加
    pcb1.event.append(eventDeviceA1)
    pcb1.event.append(eventDeviceB1)
    pcb1.event.append(eventDeviceC1)

    pcb2.event.append(eventDeviceB11)
    pcb2.event.append(eventDeviceC12)

    # 资源事件创建
    eventResourceR1 = {}
    eventResourceR1['CpuTime'] = 6
    eventResourceR1['task_application'] = 'R'
    eventResourceR1['ResourceTime'] = 2
    eventResourceR1['re_Resource'] = [3, 3, 3]
    eventResourceR1['Rrequest'] = True

    eventResourceR2 = {}
    eventResourceR2['CpuTime'] = 4
    eventResourceR2['task_application'] = 'R'
    eventResourceR2['ResourceTime'] = 1
    eventResourceR2['re_Resource'] = [2, 2, 2]
    eventResourceR2['Rrequest'] = True

    eventResourceR3 = {}
    eventResourceR3['CpuTime'] = 8
    eventResourceR3['task_application'] = 'R'
    eventResourceR3['ResourceTime'] = 2
    eventResourceR3['re_Resource'] = [1, 2, 3]
    eventResourceR3['Rrequest'] = True

    eventResourceR4 = {}
    eventResourceR4['CpuTime'] = 5
    eventResourceR4['task_application'] = 'R'
    eventResourceR4['ResourceTime'] = 1
    eventResourceR4['re_Resource'] = [4, 3, 2]
    eventResourceR4['Rrequest'] = True

    eventResourceR5 = {}
    eventResourceR5['CpuTime'] = 4
    eventResourceR5['task_application'] = 'R'
    eventResourceR5['ResourceTime'] = 1
    eventResourceR5['re_Resource'] = [3, 2, 3]
    eventResourceR5['Rrequest'] = True

    eventResourceR6 = {}
    eventResourceR6['CpuTime'] = 3
    eventResourceR6['task_application'] = 'R'
    eventResourceR6['ResourceTime'] = 1
    eventResourceR6['re_Resource'] = [2, 3, 2]
    eventResourceR6['Rrequest'] = True

    # 资源事件添加
    pcb2.event.append(eventResourceR1)
    pcb2.event.append(eventResourceR2)

    pcb3.event.append(eventResourceR3)
    pcb3.event.append(eventResourceR4)
    pcb3.event.append(eventResourceR5)
    pcb3.event.append(eventResourceR6)

    # 文件事件创建
    eventFileF1 = {}
    eventFileF1['CpuTime'] = 9
    eventFileF1['task_application'] = 'F'
    eventFileF1['Frequest'] = 'storage'
    eventFileF1['FileName'] = 'C\\First\\newText1.txt'
    eventFileF1['re_fSize'] = 10
    eventFileF1['Ftype'] = 0

    eventFileF2 = {}
    eventFileF2['CpuTime'] = 7
    eventFileF2['task_application'] = 'F'
    eventFileF2['Frequest'] = 'storage'
    eventFileF2['FileName'] = 'C\\First\\newText2.txt'
    eventFileF2['re_fSize'] = 10
    eventFileF2['Ftype'] = 0

    eventFileF3 = {}
    eventFileF3['CpuTime'] = 5
    eventFileF3['task_application'] = 'F'
    eventFileF3['Frequest'] = 'delete'
    eventFileF3['FileName'] = 'C\\First\\newText2.txt'
    eventFileF3['re_fSize'] = 10
    eventFileF3['Ftype'] = 0

    pcb4.event.append(eventFileF1)
    pcb4.event.append(eventFileF2)
    pcb4.event.append(eventFileF3)

    # 设置信号量
    semaphore = {'mex1': 1, 'mex2': 0}

    # 添加信号量事件
    eventSem1 = {}
    eventSem1['CpuTime'] = 8
    eventSem1['task_application'] = 'S'
    eventSem1['re_mutex'] = ['mex1']  #获取 1
    eventSem1['Srequest'] = True

    eventSemR1 = {}
    eventSemR1['CpuTime'] = 3
    eventSemR1['task_application'] = 'S'
    eventSemR1['re_mutex'] = ['mex2']  #释放 2 3
    eventSemR1['Srequest'] = False

    eventSem2 = {}
    eventSem2['CpuTime'] = 4
    eventSem2['task_application'] = 'S'
    eventSem2['re_mutex'] = ['mex2']  # 获取 2
    eventSem2['Srequest'] = True

    pcb4.Semaphore = semaphore
    pcb5.Semaphore = semaphore

    pcb4.event.append(eventSem1)
    pcb4.event.append(eventSemR1)
    pcb5.event.append(eventSem2)

    PCBList = [pcb1, pcb2, pcb3, pcb4, pcb5]
    iter = processManage('RR', PCBList)
    result = []
    while True:
        try:
            for dict in next(iter):
                result.append(dict)
            yield result
        except:
            yield result  # 暂时先这样
            break