blob: b7e9ad46add4502962030e7534c4711107341a7f [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <pthread.h>
5
6static void *thread_func(void *arg)
7{
8 while(1)
9 {
10 printf("thread_func\n");
11 sleep(1);
12 }
13 pthread_exit(0);
14}
15
16int main(int argc,char *argv[])
17{
18 pthread_attr_t attr;
19 pthread_t tid;
20 int s;
21
22 s = pthread_attr_init(&attr);
23 if (s != 0)
24 {
25 perror("pthread_attr_init error\n");
26 exit(-1);
27 }
28
29
30 s = pthread_create(&tid, &attr, thread_func, NULL);
31 if (s != 0)
32 {
33 perror("pthread_create error\n");
34 exit(-2);
35 }
36
37 s = pthread_join(tid, NULL);
38 if (s != 0)
39 {
40 perror("pthread_join error\n");
41 exit(-3);
42 }
43
44 return 0;
45}