pthread_create사용법

cpkhh02의 이미지

#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <stdlib.h>
#define n 10
void consumer(void); // thread function prototype
char buffer[n];
int in = 0, out = 0;

int
main ()
{
char nextp;
int i;
pthread_t tid;

pthread_create(&tid, NULL,consumer, NULL);

for (i = 0; i < 500; i++) {
while ( (in+1) % n == out) ;
buffer[in] = nextp; in++; in %= n;
}
pthread_join(tid,NULL);
return 0;
}
void consumer(void)
{
char nextc;
for(i = 0; i < 500; i++) {
while (in == out) ;
nextc = buffer[out];
out++; out %= n;
}
}

위 코드를 컴파일 하고 싶습니다..
c실력이 부족한 지라 아래와 같은 메시지가 나옵니다..
부디 도와 주세여..

pp.c: In function `main':
pp.c:17: warning: passing arg 3 of `pthread_create' from incompatible pointer type
pp.c: In function `consumer':
pp.c:30: `i' undeclared (first use in this function)
pp.c:30: (Each undeclared identifier is reported only once
pp.c:30: for each function it appears in.)

eminency의 이미지

에러는 딱 두 가지네요. pthread_create 세번째 인자가 잘못됐다는 것과 consumer 함수 안에 i가 선언되어 있지 않은 것...

세번째 인자는 man 페이지나 pthread.h에 보시면

void *(*start_routine)(void *)

라고 되어 있으니 consumer함수도 그에 맞게

void *consumer(void *arg)

로 해주세요 프로토타입도 고치시구요.

노루가 사냥꾼의 손에서 벗어나는 것 같이, 새가 그물치는 자의 손에서 벗어나는 것 같이 스스로 구원하라 -잠언 6:5

cpkhh02의 이미지

답변에 감사 드립니다.