- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
More Synchronisation Massey University更多的同步梅西大学
159.335 More Synchronisation Last time: bounded buffer, readers-writers, dining philosophers Today: sleeping barber, monitors What is the sleeping barber problem? 1 barber N waiting chairs No customers - barber sleeps Customer arrives - wakes barber if asleep Otherwise if empty chair sit down, otherwise leave shop. Barber Thread Global Variables Semaphore customers = 0; // no of waiting customers Semaphore barbers = 0; // no of waiting barbers (0 or 1) Semaphore mutex = 1; // protect critical sections int waiting=0; Barber void barber() { while(1) { wait(customers); // wait for a customer wait(mutex); // protect waiting waiting--; signal(barbers); // tell customer signal(mutex); // release lock on waiting cut_hair(); } } Customer Thread Customer void customer() { wait(mutex); // in CS if(waiting NO_CHAIRS) { // if no free chairs leave waiting++; // one more waiting customer signal(customers); // wakeup barber if necessary signal(mutex); // release lock wait(barbers); // wait until barber is free get_haircut(); } else { signal(mutex); } } Can Synchronisation be made easier? What is a Monitor? A High level synchronisation construct. i.e. Part of a programming language. Why? Semaphores are confusing because 1. Two uses - mutex and ipc 2. Can forget one of them or get in wrong order. How? Mutex: Put critical sections into separate functions and group together. This is called a monitor. IPC: use special variables for wait and signal. These are called condition variables. Monitor for Produce-Consumer monitor ProducerConsumer { condition full, empty; int count=0; void enter() { if (count == N) wait(full); ...enter item... count++; if (count == 1) signal(empty); } void remove() { if (count == 0) wait(empty); ...remove item... count--; if (count == N-1) signal(full); } } Monitor for Produce-Consumer void producer() { while(1) { ...produce item..
您可能关注的文档
- Merchandise Inventory, Cost of Goods Sold, and Gross 商品库存销售成本总成本.ppt
- Merchandising Operations and the MultipleStep 采购业务和多步.ppt
- Mercury Contamination from Metal Scrap Processing Facilities –金属废料处理设施中的汞污染.ppt
- Mercury and the Moon Midinfrared Spectroscopic Measurements水星和月亮中红外光谱测量.ppt
- MERCURY THERMOMETER SCIENCE for YOU水银温度计科学为您.ppt
- meridians and points经络与穴位.ppt
- Merry Christmas and a Happy New Year! intenziv圣诞快乐新年快乐 intenziv.ppt
- Merry Christmas and Happy New Year narod圣诞快乐和新年快乐Narod.ru.ppt
- Mesopotamia pptpaloozapptpalooza美索不达米亚.net.ppt
- Mesopotamia The Fertile Crescent Weebly肥沃的新月 weebly美索不达米亚the.ppt
- More Zoonotic Diseases pitt更多的人畜共患传染病皮特.ppt
- More Evidence for Multiple Meteorite Magmas PSRD更多的证据多陨石岩浆在.ppt
- Morning Meeting “A Powerful Way to Begin the Day”“晨会”是“一天的开始”.ppt
- Morning WarmUp Unit 1上午热身单元1.ppt
- More Zoonotic Diseases更多的人畜共患传染病.ppt
- MORGAN IMPRESORES S摩根的impresores.A. Middle States .ppt
- Morphological Evolution of Asteroids CSCAMM小行星的cscamm形态演变.ppt
- Morphological and Histochemical Features of the Duodenal十二指肠的形态学与组织化学特征.ppt
- Morphology California State University, Bakersfield加利福尼亚州立大学的形态贝克斯菲尔德.ppt
- Morphology IIIT Hyderabad该形态海得拉巴.ppt
最近下载
- 中国河湖长江之永乐江.docx VIP
- 小学一年级上册立体图形的拼搭PPT课件.pptx VIP
- 《HarmonyOS鸿蒙应用开发》电子教案--项目5-05.doc VIP
- 2023会计年终工作述职报告7篇.docx VIP
- 2025市政公用工程管理与实务.doc VIP
- 金蝶k3 wise创新管理平台plm v研发操作手册.pdf
- 海南大学《线性代数C》2022-2023学年第二学期期末试卷C卷及答案.pdf VIP
- 4.2.2.1乡镇卫生院医疗质量管理标准制度.docx VIP
- 华为HCIE-Routing&Switching实验手册V3.0.docx VIP
- 2025四川事业单位《综合知识》试题(+答案解析).docx VIP
原创力文档


文档评论(0)