生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx

上传人:b****4 文档编号:14134778 上传时间:2022-10-19 格式:DOCX 页数:13 大小:97.37KB
下载 相关 举报
生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx_第1页
第1页 / 共13页
生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx_第2页
第2页 / 共13页
生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx_第3页
第3页 / 共13页
生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx_第4页
第4页 / 共13页
生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx

《生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx(13页珍藏版)》请在冰豆网上搜索。

生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx

Student’sID:

DateofSubmission:

Dec20,2011

TableofContents

RequirementofProject……………………………………………………………………………………….3

OperatingEnvironment…………………………………………………………..………….………………3

PrincipleofProgram………………………………………………………..………….………………………3

Structure……………………………………………………………………………………………………………………3

FlowChart…………………………………………………………………………………………………………………4

CodeoftheProgram……………………………………………………………………………..……………………5

ResultsofSimulation…………………………………………………………………………….…………………….8

ConsiderableImprovement…………………………………………………………………………………9

Conclusion……………………………………………………………………………..……………………………11

References……………………………………………………………………………………………..……………12

RequirementofProject

Theproducer-consumerproblemillustratedasthemodelofbounded-buffer,requiresequentialprocessesorthreadsrunningasynchronouslyandpossiblysharingdata.Thereareseveralmethodstosolvethisproblem,andsemaphore,mutex(simplifiedsemaphore)andmonitorarecommonlyusedonthis.Thisprojectrequiresustomakeproducersandconsumers–runningasseparatedthreads,andsemaphoreswithfull,empty,andmutexparameterstosimulatethisprocedure.

Inthetextbook,wearesuggestedtousePthreadsorWin32API,however,IdecidedtouseJavatosimulatetheprocedure,becauseJavaisthemostfamiliarlanguagethatwehavelearned.

BecauseoftheJavaVirtualMachine(JVM)layer,manystructuresaremadesimpleinJavacomparedtowin32APIandCinUNIXenvironment,andwecansimulatetheproblemwithoutacertainsemaphore.

OperatingEnvironment

OS:

Windows7,

JDK:

Java7edition1.7.0_02

PrincipleofProgram

BecauseofthelimitedJavaprogrammingskills,Icanonlysimulatetheprocedureinthemostsimplifiedway.Onlythreesub-classesareputundertheProducerConsumerClassintheprogram,andonlyonemethodwhichisthenecessarymainvoidmethodinthisClass.

Thethreesub-classesarestorage,producerandconsumer,andproducerandconsumerclassesaresetasJavathreads,becausetheyextendlibraryclassofThreadinjava.lang.Objectpackage.

Thereareseveralobjectsandmethodsinthesethreesub-classes,andtheyarecarefullydefinedasprivate,publicorsynchronized.

Structure:

Thefullstructureofwholeprogramisillustratedinthetablebelow.

SuperClass:

ProducerConsumer

WithObject:

p1~p7(sevenproducerobjects),c1~c3(threeconsumerobjects)

Withmethod:

main

Sub-class:

Godown//storageclass

Innervariable:

max_size,curnum//thenumberthatthestoragehavecurrently

Innermethod:

produce(int),consume(int)

Producer

Innervariable:

neednum//numberofproducing

run//inheritfromtheThreadClassinjava.lang.Object

Consumer

neednum//numberofconsuming

FlowChart:

Theflowchartofthisprogramisillustratedasbelow:

Thekeyofrealizationofthisprocedureisthatmakeeachtheproducerandconsumerarealjavathread.BylookinguptheofficialjavadocinOracleWebsites,wecanfinddetailsoftheclassThreadinjava.lang.Objectpackages.Ifindsomemethodsandexamplesofusage,andbythefunctionsandmethodsprovidedbyofficial,IusethemethodofnotifyAll(),wait().

Tableofmethodsofjava.lang.Objectinofficialjavadocisshownbelow:

MethodSummary

protected 

Object

clone() 

Createsandreturnsacopyofthisobject.

boolean

equals(Object 

obj) 

Indicateswhethersomeotherobjectis"

equalto"

thisone.

void

finalize() 

Calledbythegarbagecollectoronanobjectwhengarbagecollectiondeterminesthattherearenomorereferencestotheobject.

Class<

?

>

getClass() 

Returnstheruntimeclassofthis 

Object.

int

hashCode() 

Returnsahashcodevaluefortheobject.

notify() 

Wakesupasinglethreadthatiswaitingonthisobject'

smonitor.

notifyAll() 

Wakesupallthreadsthatarewaitingonthisobject'

String

toString() 

Returnsastringrepresentationoftheobject.

wait() 

Causesthecurrentthreadtowaituntilanotherthreadinvokesthe 

methodorthe 

methodforthisobject.

wait(long 

timeout) 

Causesthecurrentthreadtowaituntileitheranotherthreadinvokesthe 

methodforthisobject,oraspecifiedamountoftimehaselapsed.

timeout,int 

nanos) 

methodforthisobject,orsomeotherthreadinterruptsthecurrentthread,oracertainamountofrealtimeh

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 书信模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1