操作系统课程设计(设备管理)(3)

2025-07-14

河北大学工商学院操作系统课程设计

{ str = true; } break; } }

return str; } //

////////////分配设备,返回第几个设备被占用//////////////////////// //

public int Allocate(DeviceType type) { int k = 0;

switch (type) //使用switch语句选择分配设备不同函数 { case DeviceType.A: { table[0].total--;

for (int i = 0; i < 3; i++) { if (table[0].useState[i] == 0) { table[0].useState[i] = 1; k = i; break; } } break; }

case DeviceType.B: { table[1].total--;

for (int i = 0; i < 2; i++) {

if (table[0].useState[i] == 0) { table[0].useState[i] = 1; k = i; break; } } break; }

9

河北大学工商学院操作系统课程设计

case DeviceType.C: { table[2].total--; break; } } return k; } //

//////////////////////////回收设备//////////////////////////// //

public void DeAllocate(DeviceType type, int a) { switch (type)

{ case DeviceType.A: { table[0].total++;

table[0].useState[a] = 0; break; }

case DeviceType.B: { table[1].total++;

table[1].useState[a] = 0; break; }

case DeviceType.C: { table[2].total++;

table[2].useState[a] = 0; break; } } }

}

public Form1()

{ InitializeComponent(); } //

10

河北大学工商学院操作系统课程设计

///////////////////// 分配设备时的颜色变化//////////////////// //

private void button7_Click(object sender, EventArgs e) { Anum--;

string result1 = \ Device d1 = new Device();

int m1 = d1.Allocate(DeviceType.A); result1 = Convert.ToString(m1); switch (Anum) { case 2:

this.button1.BackColor = Color.Red; break; case 1:

this.button2.BackColor = Color.Red; break; case 0:

this.button3.BackColor = Color.Red; break; default:

MessageBox.Show(\无设备可分配\ break; } }

private void button8_Click(object sender, EventArgs e) { Bnum--;

string result2 = \ Device d2 = new Device();

int m2 = d2.Allocate(DeviceType.B); switch (Bnum) { case 1:

this.button4.BackColor = Color.Red; break; case 0:

this.button5.BackColor = Color.Red; break;

11

河北大学工商学院操作系统课程设计

default:

MessageBox.Show(\无设备可分配\ break; }

result2 = Convert.ToString(m2); }

private void button9_Click(object sender, EventArgs e) { Cnum--;

string result3 = \ Device d1 = new Device();

int m3 = d1.Allocate(DeviceType.C); if (Cnum == 0)

{ this.button6.BackColor = Color.Red; } else

{ MessageBox.Show(\无设备可分配\ }

result3 = Convert.ToString(m3);

}

} }

4.5 运行截图

屏幕显示

主存使用情况示意图,哪些主存块已分配,哪些主存块未分配,以不同的颜色表示,灰色表示设备空闲,红色表示设备已分配

初始化为所有设备都是空闲状态,如下图所示

12

河北大学工商学院操作系统课程设计

图4-2

分配设备A正常情况下,如图所示:

图4-3

13


操作系统课程设计(设备管理)(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2024 地域文化(岭南民间文化)--任务二(综合练习)

相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219