typedef struct cList{ struct cList *next; int val; }* cListe; cListe li; pthread_mutex_t mut; void *consume(void *p){ int ret; cListe temp; while(any){ ret=pthread_mutex_lock(&mut); if(li!=NULL){ temp=li->next; if(temp==li) { free(temp); li=NULL; } else { while(temp->next!=li){ temp=temp->next; } temp->next=li->next; free(li); li=temp; } } ret=pthread_mutex_unlock(&mut); } } void *produce(void *p){ int ret; cListe temp; while(any){ ret=pthread_mutex_lock(&mut); temp=malloc(sizeof(struct cList)); temp->next=li; temp->val=1; if(li==NULL){ temp->next=temp; } else{ temp->next=li->next; li->next=temp; } li=temp; ret=pthread_mutex_unlock(&mut); } } int main(){ pthread_t th1; pthread_t th2; int ret; ret=pthread_mutex_init(&mut,NULL); ret=pthread_create(&th2,NULL,produce,NULL); ret=pthread_create(&th1,NULL,consume,NULL); ret=pthread_join(th1,NULL); ret=pthread_join(th2,NULL); }