过桥问题课设报告.docx
- 文档编号:1609538
- 上传时间:2022-10-23
- 格式:DOCX
- 页数:16
- 大小:329.68KB
过桥问题课设报告.docx
《过桥问题课设报告.docx》由会员分享,可在线阅读,更多相关《过桥问题课设报告.docx(16页珍藏版)》请在冰豆网上搜索。
过桥问题课设报告
操作系统课程设计报告书
题目过桥问题
系别计算机工程系
专业计算机科学与技术
班级
姓名
指导教师
下达日期2013年6月15日
设计时间自2013年6月17日至2013年6月30日
第一章课程设计目的
该课程是在学完《操作系统》课程之后,让学生在掌握基本原理和方法的基础上,运用熟悉的开发工具,在计算机上模拟实现操作系统课程中介绍的操作和算法。
以帮助同学切身体验各种操作的过程及效果,同时加深同学对基本原理的理解,提高同学的编程能力、综合应用知识的能力和分析解决问题的能力,初步培养研制简单系统程序开发的能力。
第二章课程设计内容与要求
掌握并发进程中同步与互斥的机制,基于线程的编程技术开发类似生产者—消费者问题的演示程序。
模拟程序的开发不但要正确体现原算法的基本原理,还要精心设计,充分体现学生自身在演示过程设计中的独特性,使模拟程序演示过程清晰、准确,演示的效果直观、图文并茂,达到能够帮助学生更深入的理解算法的目的。
第三章过桥Pv操作
过桥的规则:
同一方向的可连续过桥,某方向有人过桥时另一方向的人要等待。
//mutex—左右两边过桥的互斥信号量;Lcount,Rcount—左右两边过桥人数
//Lmutex,Rmutex—分别表示对Lcount,Rcount互斥访问的信号量
VarSemaphoremutex,Lmutex,Rmutex=1,0,0;
intLcount=0,Rcount=0;
Main()
{cobegin
Left();Right();
Coend}
Left()
{while(true)
{P(Lmutex);
ifLcount==0P(mutex);
Lcount=Lcount+1;
V(Lmutex)
过桥;
p(Lmutex);
ifLcount==0V(mutex);
Lcount=Lcount-1;
V(Lmutex)}
}
Right()
{while(true)
{P(Rmutex);
ifRcount==0P(mutex);
Rcount=Rcount+1;
V(Rmutex)
过桥;
p(Rmutex);
ifRcount==0V(mutex);
Rcount=Rcount-1;
V(Rmutex)}
}
第四章源代码
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Threading;
usingSystem.Collections;
namespaceCrossBridge
{
publicpartialclassForm1:
Form
{
//intbridge=0;//0:
空闲
intleftCount=0;
intrightCount=0;
inttime=3000;
IListlist=newArrayList();
privatedelegatevoidSetTextBoxCallBack(stringstr);
privatedelegatevoidSetTBInBridge(intvalue);
SetTextBoxCallBacksetTB;
SetTBInBridgesetBridge;
publicForm1()
{
InitializeComponent();
setTB=newSetTextBoxCallBack(SetTextBox);
setBridge=newSetTBInBridge(SetTextBoxInBridge);
}
voidSetTextBox(stringstr)
{
textBox1.AppendText(str+System.Environment.NewLine);
}
voidSetTextBoxInBridge(intvalue)
{
textBox5.Text=value.ToString();
}
privatevoidbtleft_Click(objectsender,EventArgse)
{
Threadthread1=newThread(newThreadStart(LeftHonkey));
thread1.Name=System.DateTime.Now.ToString();
//list.Add(thread1);
thread1.Start();
}
privatevoidbtright_Click(objectsender,EventArgse)
{
Threadthread1=newThread(newThreadStart(RightHonkey));
//list.Add(thread1);
thread1.Name=System.DateTime.Now.ToString();
thread1.Start();
}
publicvoidLeftHonkey()
{
lock(this)
{
while(rightCount>0)
{
try
{
textBox5.Invoke(setBridge,rightCount+leftCount);
textBox1.Invoke(setTB,Thread.CurrentThread.ManagedThreadId+"左猴子阻塞");
Monitor.Wait(this);
}
catch(System.Exceptionex)
{
}
}
leftCount++;
textBox5.Invoke(setBridge,rightCount+leftCount);
textBox1.Invoke(setTB,Thread.CurrentThread.Name+"左猴子上桥");
Monitor.PulseAll(this);
}
Thread.Sleep(int.Parse(textBox2.Text.Trim())*1000);
lock(this)
{
leftCount--;
textBox5.Invoke(setBridge,rightCount+leftCount);
textBox1.Invoke(setTB,Thread.CurrentThread.Name+"左猴子通过");
Monitor.PulseAll(this);
}
}
publicvoidRightHonkey()
{
lock(this)
{
while(leftCount>0)
{
try
{
textBox5.Invoke(setBridge,rightCount+leftCount);
textBox1.Invoke(setTB,Thread.CurrentThread.Name+"右猴子阻塞");
Monitor.Wait(this);
}
catch(System.Exceptionex)
{
}
}
rightCount++;
textBox5.Invoke(setBridge,rightCount+leftCount);
textBox1.Invoke(setTB,Thread.CurrentThread.Name+"右猴子上桥");
Monitor.PulseAll(this);
}
Thread.Sleep(int.Parse(textBox2.Text.Trim())*1000);
lock(this)
{
rightCount--;
textBox5.Invoke(setBridge,rightCount+leftCount);
textBox1.Invoke(setTB,Thread.CurrentThread.Name+"右猴子通过");
Monitor.PulseAll(this);
}
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
}
}
}
namespaceCrossBridge
{
partialclassForm1
{
///
///必需的设计器变量。
///
privateSystem.ComponentModel.IContainercomponents=null;
///
///清理所有正在使用的资源。
///
///
protectedoverridevoidDispose(booldisposing)
{
if(disposing&&(components!
=null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#regionWindows窗体设计器生成的代码
///
///设计器支持所需的方法-不要
///使用代码编辑器修改此方法的内容。
///
privatevoidInitializeComponent()
{
this.textBox1=newSystem.Windows.Forms.TextBox();
this.label1=newSystem.Windows.Forms.Label();
this.textBox2=newSystem.Windows.Forms.TextBox();
this.label2=newSystem.Windows.Forms.Label();
this.textBox3=newSystem.Windows.Forms.TextBox();
this.label3=newSystem.Windows.Forms.Label();
this.textBox4=newSystem.Windows.Forms.TextBox();
this.label4=newSystem.Windows.Forms.Label();
this.label5=newSystem.Windows.Forms.Label();
this.btleft
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 过桥 问题 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)