Intro 本文为多生产者多消费者的C语言实现 生产者与消费者针对链表的头结点进行操作 使用到的线程同步方法为互斥锁+条件变量 本文侧重于理解条件变量的使用 为保证代码简洁,本文代码没有对函数的返回值进行检查,聪明的你一定知道如何检查这个小细节(•̀ᴗ•́)و ̑̑ show me the code /* 基于链表的多生产者多消费者问题 */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <pthread.h> struct Node{ int number; struct Node* next; };//链表 pthread_mutex_t mutex;//互斥锁 pthread_cond_t cond;//条件变量,用于控制消费者 struct Node *head = NULL;//链表头结点指针 void *producer(void *arg);//生产者 void *consumer(void *arg);//消费者 void Init(pthread_t *ptid, pthread_t *ctid); void Dest(pthread_t *ptid, pthread_t *ctid); int main(int argc, char **argv)