叫醒睡着的理发师问题----操作系统

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include  
#include 
using namespace std;
#define MAXCHAIR 3
#define MAX_THREAD_NUM 10
int chairs,thread_id;
HANDLE h_Mutex, h_Barber, h_Customer;//信号量
//使用WINAPI创线程
DWORD WINAPI CustomerThread(void *p);
DWORD WINAPI BaberThread(void *p);
DWORD WINAPI BaberThread(void *p)
{
    while(1)
    {
        WaitForSingleObject(h_Customer,-1);//P信号量
        WaitForSingleObject(h_Mutex,-1);//P信号量
        chairs++;//空位+1
        ReleaseSemaphore(h_Barber,1,NULL);//V信号量
        ResumeThread((HANDLE)CustomerThread);//唤醒等待顾客
        ReleaseMutex(h_Mutex);//V信号量
        cout <<"*************理发师开始理发!"< 0)//有等待位置
    {
        chairs--;
        cout<<"顾客 "<>num;
    if(num<1||num>2)
    {
        cout<<"输入无效,请重新输入"<

 

你可能感兴趣的:(操作系统)