用vc++模拟多线程同步和互斥(生产者消费者问题)。
现在定义如下信号量:
HANDLE m_S_Empty; // 生产者Semaphore
HANDLE m_S_Full; // 消费者Semaphore
HANDLE m_M_Mutex; //互斥
//----------------------------
m_S_Empty = CreateSemaphore(NULL,N,N,NULL);//初始计数为N
m_S_Full = CreateSemaphore(NULL,0,N,NULL);//初始计数为0
m_M_Mutex = CreateMutex(NULL,FALSE,NULL);//
然后,用
if (WaitForSingleObject(m_S_Full,INFINITE) == WAIT_OBJECT_0)
以及
if (WaitForSingleObject(m_M_Mutex,INFINITE) == WAIT_OBJECT_0)
实现线程同步和互斥。
现在问题是,我能不能实时知道,m_M_Mutex,m_S_Empty,m_S_Full这三个信号量的值?