링크드리스트로 구현한 큐와 pthread 질문
글쓴이: i1004gy / 작성시간: 금, 2021/04/23 - 1:22오전
제가 링크드 리스트로 큐를 구현하고 이것을 가지고 pthread로 돌릴려고 하는데 계속 오류가 나오네요 무슨 문법이 잘못된질 모르니까 해결도 못하겠고
pthread_create이 부분에서 Queue_enqueue부분에서 에러가 납니다
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> #include <pthread.h> #include <assert.h> typedef struct _node_t{ int value; struct _node_t *next; } node_t; typedef struct _queue_t{ node_t *head; node_t *tail; pthread_mutex_t headLock; pthread_mutex_t tailLock; }queue_t; void Queue_Iint(queue_t *q){ node_t *tmp = malloc(sizeof(node_t)); tmp->next = NULL; q->head = q-> tail =tmp; pthread_mutex_init(&q->headLock, NULL); pthread_mutex_init(&q->tailLock,NULL); } void Queue_Enqueue(queue_t *q, int value){ node_t *tmp = malloc(sizeof(node_t)); assert(tmp != NULL); tmp->value =value; tmp -> next = NULL; pthread_mutex_lock(&q->tailLock); q->tail->next = tmp; q->tail=tmp; pthread_mutex_unlock(&q->tailLock); } int Queue_Dequeue(queue_t *q, int *value){ pthread_mutex_lock(&q->headLock); node_t *tmp = q->head; node_t *newHead =tmp->next; if(newHead ==NULL){ pthread_mutex_unlock(&q->headLock); return -1; } *value = newHead->value; q->head = newHead; pthread_mutex_unlock(&q->headLock); int re=tmp->value; free(tmp); return re; } int main(){ queue_t q; Queue_Iint(&q); pthread_t p1, p2,p3,p4,p5; int rc; rc=pthread_create(&p1,NULL,*Queue_Enqueue,(int*)3); assert(rc==0); rc= pthread_join(p1,NULL); assert(rc==0); return 0; }
Forums:
pthread_create(,*Queue
pthread_create(,*Queue_Enqueue,) 가 아니라 pthread_create(,Queue_Enqueue,) 로 하셔야 합니다.
* 가 없어요.
댓글 달기