[질문] thread 소스 컴파일하는데 애러 나요. 왜 이러죠?
아래 소스를
cc -o pt -l pthread pt.c
이렇게 컴파일 하는데
cc -o pt -l pthread pt.c
"pt.c", line 24.68: 1506-280 (W) Function argument assignment between types "void*(*)(void*)" and "void(*)()" is not allowed.
이렇게 애러가 나요.
왜 이러죠...?
+1 #include <stdio.h>
+2 #include <errno.h>
+3 #include <pthread.h>
+4
+5 #define SUM_NUM 50000
+6 #define THREAD_NUM 10
+7
+8 void pth_routine();
+9
+10 int s;
+11
+12 main()
+13 {
+14 int i;
+15 pthread_t pth[THREAD_NUM];
+16 pthread_mutex_t ptm;
+17
+18 /* mutex lock 초기화 */
+19 if(pthread_mutex_init(&ptm, (pthread_mutexattr_t *)NULL) != 0)
+20 perror("pthread_mutex_init():");
+21
+22 /* thread 생성 */
+23 for(i = 0; i < THREAD_NUM; i++)
+24 if(pthread_create(&pth[i], (pthread_attr_t *)NULL, pth_routine, (void *)&ptm) != 0)
+25 perror("pthread_create():");
+26
+27 /* thread 모두 종료할 때 까지 대기 */
+28 for(i = 0; i < THREAD_NUM; i ++)
+29 if(pthread_join(pth[i], (void **)NULL) != 0)
+30 perror("pthread_join():");
+31
+32 printf("정상값은 %d << %d >>\n", SUM_NUM * THREAD_NUM, s);
+33 }
+34
+35 void pth_routine(pthread_mutex_t *ptm)
+36 {
+37 int i;
+38
+39 printf("thread_ID : %d\n", pthread_self());
+40
+41 for(i = 0; i < SUM_NUM; i++) {
+42 pthread_mutex_lock(ptm);
+43 s++;
+44 pthread_mutex_unlock(ptm);
+45 }
+46 }
pthread로 실행되는 함수 형태는 void* start_routine(void* )
내 블로그: http://unipro.tistory.com
댓글 달기