信号量解决理发师问题(barber)
Posted lqerio
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了信号量解决理发师问题(barber)相关的知识,希望对你有一定的参考价值。
问题描述及思路
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-a9fb6fe96be53219.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-f4c87233b4cbcea3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-a9b4dec50cda406e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-9ba9819eeafe2551.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
代码
一些细节见注释
这里ret应该用int。。忘了改了。
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-f26ed98bb35eb5fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-86ee3d745ebd1ad8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-b9e1a929799ac362.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-a5094622ec8bbe2e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
运行结果
因为座位数和到来最大间隔的原因,没有出现全部椅子被占用的情况
![技术图片](https://upload-images.jianshu.io/upload_images/16981913-95ebc8b61579e7d0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
以上是关于信号量解决理发师问题(barber)的主要内容,如果未能解决你的问题,请参考以下文章