小编Twi*_*876的帖子

使用信号量和pthreads的Producer Consumer程序

我已经为生产者 - 消费者问题写了一个代码.但是我没有得到输出.没有编译错误,但在我的程序中发出警告.我很困惑.非常努力.但是无法得到它.请告诉我什么我的程序是错的.什么是正确的程序.我感到沮丧.请帮助伙计们.这是代码 -

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include </usr/include/semaphore.h>

#define BUFF_SIZE   5           /* total number of slots */
#define NP          3           /* total number of producers */
#define NC          3           /* total number of consumers */
#define NITERS      4           /* number of items produced/consumed */

typedef struct {
    int buf[BUFF_SIZE];   /* shared var */
    int in;               /* buf[in%BUFF_SIZE] is the first empty slot */
    int out;              /* buf[out%BUFF_SIZE] is the first full slot */
    sem_t full;           /* …
Run Code Online (Sandbox Code Playgroud)

c semaphore pthreads

9
推荐指数
1
解决办法
6万
查看次数

标签 统计

c ×1

pthreads ×1

semaphore ×1