程序排程演算法

2022-12-11 04:33:03 字數 4066 閱讀 4107

執行緒函式返回是確保所有執行緒資源被正確地清除的唯一辦法。

4、 程序排程常用演算法的相關知識參考課堂《計算機作業系統》教材

5、 mfc棧(queue),鍊錶(list),向量(vector) 相關知識參考msdn**或光碟

實驗指導

1、 程序相關的資料結構

//程序狀態

enum procstatus

;//程序優先順序

enum procpriority

;//排程演算法

enum schedulealgorithm

;//程序識別符號

struct procid

;//處理機狀態

struct processorstatus

;//程序排程資訊

struct procschinfo

;//程序控制資訊

struct procconinfo

;//程式

struct program

;//統計資訊

struct statinfo

;//程序控制塊

struct pcb

;//統計資訊:程式長度

struct statinfo_proglen

};//統計資訊:程序優先順序

struct statinfo_priority

};2、 程序排程演算法和效能測試程式的主要模組

dword winapi getrandproc(lpvoid lpparam); //產生隨機隨機程序並插入就緒佇列

void schedule_fcfsfcfs排程

void schedule_spf短作業優先

void schedule_fpf_re**ed高優先權排程

void schedule_timepiece時間片排程

void schedule排程程式

bool runproc(pcb *ppcb執行程序

void exit退出系統

void pressanykey按任意鍵繼續

void coolbeep(uint uicbsort蜂鳴聲

void reset(schedulealgorithm algo); //重新設定初值

void printpriority(procpriority p); //以文字方式列印優先順序

bool ctrlhandler(dword dwctrltype); //處理控制台事件

void clean事後清理

void printalgorithm(schedulealgorithm algo); //列印演算法

//列印統計資訊:程式長度

void printstatinfo_proglen(statinfol_proglen l,schedulealgorithm algo);

//列印統計資訊:程序優先順序

void printstatinfo_priority(statinfol_priority l,schedulealgorithm algo);

void sortinsproglenq(pcbpqueue& pcbq,pcb pcb); //按程式大小入佇列

void sortinspriorityq(pcbpqueue& pcbq,pcb pcb); //按優先順序入佇列

3、 全域性變數

intg_nclosetime模擬時間

intg_nmaxruntime程式最大執行時間

intg_nmaxinterval最大間隔

intg_nmaxtimepiece最大時間片

intg_ncurprocid=0當前程序id

pcbg_currunningproc當前正在執行的程序

intg_nfinishedtime=0模擬已完成的時間

boolg_bisend=false結束標誌

boolg_bprogisrun是否有程式正在執行

boolg_bisprioritierreach=false; //是否有優先順序更高的程序達到

pcbg_pcbprioritier更高優先順序的程序

pcbqueueg_pcbreadyqueue就緒佇列

pcbpqueueg_pcbreadypriorityqueue; //就緒優先順序佇列

schedulealgorithm g_schedulealgorithm排程演算法

critical_section g_criticalsection臨界區

statinfol_proglen g_liststatinfoproglen[3]; //統計資訊鍊錶:程式長度

statinfol_priority g_liststatinfoprocpriority; //統計資訊鍊錶:程序優先順序

handle g_hstdout=getstdhandle(std_output_handle); //標準輸出(控制台控制代碼)

4、 自定義巨集

//顏色

#define clr_green 10 //綠

#define clr_red 12 //紅

#define clr_secred 13 //次紅

#define clr_yellow 14 //黃

#define clr_inclr_red輸入顏色

#define clr_normaloutclr_green //一般輸出顏色

#define clr_criticaloutclr_red重要輸出顏色

#define clr_normalresult clr_yellow //一般結果輸出顏色

#define clr_criticalresult clr_red重要結果輸出

#define clr_seccriticalresult clr_secred //次重要結果輸出

//聲音型別

#define cb_error 0 //錯誤

#define cb_ok 1 //正確

#define randdf rand()*1.0/rand_max產生0~1之間的隨機小數

struct pcb;

struct pcbprioritycompare;

struct pcbproglencompare;

struct statinfo_proglen;

struct statinfo_priority;

typedef intinstruction指令

typedef queuepcbqueue程序控制塊佇列

typedef listpcbpqueue程序控制塊優先順序佇列

typedef vector instructionset指令集合

typedef list statinfol_proglen; //統計資訊鍊錶:程式長度

typedef list statinfol_priority; //統計資訊鍊錶:程序優先順序

5、 參考程式

//主函式

int main(int argc, tchar* ar**, tchar* envp){…

uchar ucselection;//選擇號

srand(time(0));

initializecriticalsection(&g_criticalsection);

setconsoletitle("程序排程演算法演示及其效能測試系統");//設定標題

setconsolectrlhandler((phandler_routine)ctrlhandler,true);

…ucselection=getch();

…switch(ucselection)

{case '1':

case '2':

case '3':

case '4':

g_schedulealgorithm=(schedulealgorithm)(ucselection-'1'+fcfs);

cache排程演算法

在虛擬儲存器中,當發生頁面失效時,需要從磁碟儲存器中調入一頁 或一段 到主儲存器中。在段式和段頁式虛擬儲存器中,由於多使用者虛頁數比主儲存器的實頁數要多得多。在段式虛擬儲存器中,虛存空間中能容納的程式段數要比主存空間中能存放的相同長度的程式段數多得多。因此,必然會出現當主存中所有頁面都已經被占用,或...

作業程序排程演算法設計與實現作業系統實驗報告

實驗報告 課程名稱 實驗專案 實驗儀器 院系計算機學院 專業電腦科學與技術 班級 學號計0503 29 學生姓名楊天心 實驗日期 成績指導老師 實驗二作業 程序排程演算法設計與實現 一 實驗目的 排程是作業系統的主要功能,本實驗通過自行設計實現的排程程式,使同學們加深對作業 程序排程功能的理解,從而...

模擬程序排程程式

一實驗目的 程序及程序管理是作業系統最重要的內容之一。本實驗要求學生選用某種程序排程演算法用 c 語言編制模擬程序排程的程式,並在機器上執行通過。通過本實驗,使學生對程序排程的演算法 資料結構及其實現程式有乙個較為深入具體的了解。二實驗題 第一題設計乙個按時間片輪轉演算法排程的模擬程式。1,設系統中...