69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
pthread_t tid1,tid2,tid3,tid4;
struct job{
struct job *prev;
struct job *next;
pthread_t id;
};
struct myqueue{
struct job *head;
struct job *tail;
pthread_rwlock_t qlock; /* protect head and tail pointer */
};
struct myqueue *qp;
struct job *job1,*job2,*job3,*job4;
int init_queue()
{
int err;
/* initializing work queue*/
qp = (struct myqueue*)calloc(1,sizeof(struct myqueue*)); /* calloc(): clean up */
err = pthread_rwlock_init(&qp->qlock, NULL); /* 注释掉该行,可以释放qp */
if(err != 0)
return err;
/* initializing jobs */
job1 = (struct job*)calloc(1,sizeof(struct job*));
job2 = (struct job*)calloc(1,sizeof(struct job*));
job3 = (struct job*)calloc(1,sizeof(struct job*));
job4 = (struct job*)calloc(1,sizeof(struct job*));
}
int main()
{
/* 1.initializing queue and jobs */
init_queue();
pthread_rwlock_destroy(&qp->qlock);
free(qp); /* 该行出现问题 */
return 0;
}