【生产者消费者问题】PV操作有些问题


#include<iostream>
#include <stdio.h>
#include <fstream>
#include<semaphore.h>
#include <pthread.h>
#include<mutex>
#include<queue>
#include<unistd.h>
using namespace std;


pthread_mutex_t _mutex;//
int producterNum=10,consumerNum=10,buffNum=10;        // input quantity
int buffer[10]={0};
sem_t signal_producer;
sem_t signal_consumer;


void* producter(void *a)
{
  pthread_mutex_lock(&_mutex);
  
  if(sem_wait(&signal_producer)!=0)  ///  P  caozuo
      cout<<"producter is waitting"<<endl;    //////
 
  cout<<"producter put something to buff"<<endl;

 
  
  sem_post(&signal_consumer);/////      V    caozuo
  
   pthread_mutex_unlock(&_mutex);

}
void* consumer(void *a)
{
   
  pthread_mutex_lock(&_mutex);

  if(sem_wait(&signal_consumer)!=0)          ////p
      cout<<"consumer is waitting"<<endl;
  

  cout<<"consumer get something from buff"<<endl;

  

  sem_post(&signal_producer);/////     V

  pthread_mutex_unlock(&_mutex);
  

}


int main(int argc, char *argv[])
{
    int i;
    cout<<"input the quantity of producter[]"<<endl;
    cin>>producterNum;
     cout<<"input the quantity of consumer[]"<<endl;
    cin>>consumerNum;
     cout<<"input the quantity of buffer[]"<<endl;
    cin>>buffNum;
    
    ////////////////////////////////////////
    sem_init(&signal_producer,0,buffNum);/// ???????????
    sem_init(&signal_consumer,0,0);
    ////////////////////////////////////////
    pthread_t thread_consumer[consumerNum],thread_producter[producterNum];
    
    pthread_mutex_init(&_mutex,NULL);
    
    for(i=0;i<producterNum;i++)
    pthread_create(&thread_producter[i],NULL,&producter, NULL);  

    for(i=0;i<consumerNum;i++)
    pthread_create(&thread_consumer[i],NULL,&consumer, NULL);

  
    for(i=0;i<producterNum;i++)
    pthread_join(thread_producter[i],NULL);
    for(i=0;i<consumerNum;i++)
    pthread_join(thread_consumer[i],NULL);


    pthread_mutex_destroy(&_mutex);
    sem_destroy(&signal_consumer);
    sem_destroy(&signal_producer);
    



}

用sem_t定义了两个信号量 signal_producter 和 signal_consumer 按说 signal_producter 初始是n, signal_consumer是0才对
可运行后不出结果,但是把他俩反过来就能出结果,但消费者先拿东西显然不合理

你的意思是68、69行中最后一个参数要交换一下吗?