生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx
- 文档编号:14134778
- 上传时间:2022-10-19
- 格式:DOCX
- 页数:13
- 大小:97.37KB
生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx
《生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《生产者消费者问题操作系统课程设计英文Word文档下载推荐.docx(13页珍藏版)》请在冰豆网上搜索。
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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 生产者 消费者 问题 操作系统 课程设计 英文