| #include <stdio.h> |
| #include <stdlib.h> |
| #include <unistd.h> |
| #include <pthread.h> |
| |
| static void *thread_func(void *arg) |
| { |
| char buffer[10]; |
| |
| while(1) |
| { |
| printf("thread_func\n"); |
| sleep(1); |
| } |
| pthread_exit(0); |
| } |
| |
| int main(int argc,char *argv[]) |
| { |
| pthread_attr_t attr; |
| pthread_t tid; |
| int s; |
| |
| s = pthread_attr_init(&attr); |
| if (s != 0) |
| { |
| perror("pthread_attr_init error\n"); |
| exit(-1); |
| } |
| |
| |
| s = pthread_create(&tid, &attr, thread_func, NULL); |
| if (s != 0) |
| { |
| perror("pthread_create error\n"); |
| exit(-2); |
| } |
| |
| s = pthread_join(tid, NULL); |
| if (s != 0) |
| { |
| perror("pthread_join error\n"); |
| exit(-3); |
| } |
| |
| return 0; |
| } |