- 论坛徽章:
- 0
|
- 1 #include <stdio.h>
- 2 #include <stdlib.h>
- 3 #include <pthread.h>
- 4
- 5 void cleanup(void *arg)
- 6 {
- 7 printf("cleanup :%s\n",(char *)arg);
- 8 }
- 9
- 10 void *thread1(void *arg)
- 11 {
- 12 pthread_cleanup_push(cleanup,"thread1");
- 13 pthread_exit((void *)1);
- 14 }
- 15
- 16 int main()
- 17 {
- 18 pthread_t tid1;
- 19 pthread_create(&tid1, NULL, thread1, NULL);
- 20 pthread_join(tid1, NULL);
- 21 exit(0);
- 22 }
复制代码
报错:
-laptop:~/test$ gcc pt1.c -lpthread
pt1.c: In function ‘thread1’:
pt1.c:16: error: expected ‘while’ before ‘int’
pt1.c:22: error: expected declaration or statement at end of input
pt1.c:22: error: expected declaration or statement at end of input |
|