我正在尝试解决消费者/生产者问题,我必须创建三个不同的类.
主类包括线程的创建和消费者/生产者逻辑
另外两个类是
我在尝试编译时遇到以下错误:
ringbuf.c: In function ‘rb_init’:
ringbuf.c:10: warning: incompatible implicit declaration of built-in function ‘malloc’
ringbuf.c:10: error: invalid application of ‘sizeof’ to incomplete type ‘struct ringbuf_t’
ringbuf.c:12: error: dereferencing pointer to incomplete type
Run Code Online (Sandbox Code Playgroud)
我还有很多其他的错误,但是一旦我完成这个错误,我就可以自己处理.
这是缓冲区的头文件:
struct ringbuf_t
{
pthread_mutex_t mutex; /* lock to protect from simutaneous access to the buffer */
pthread_cond_t cond_full; /* producer needs to wait when the buffer is full */
pthread_cond_t cond_empty; /* consumer needs to wait when the buffer is empty …Run Code Online (Sandbox Code Playgroud)