PV操作的互斥和同步
#include<semaphore.h>
#include<stdio.h>
#include<pthread.h>
#define MAXSIZE 1024
char *buffer;
int running = 1;
sem_t productor;
sem_t consumer;
void *product()//生产者
{
while(running)
{
sem_wait(&productor);//P操作
printf("input something to memory: ");
buffer = (char *)malloc(MAXSIZE);//为指针分配空间
if(fgets(buffer,MAXSIZE,stdin) == NULL)//用gets写入
{
perror("fail to fgets");
sem_post(&consumer);
}
//sem_post(&consumer);
if(strncmp(buffer,"end",3) &#