blob: 2f25b93f192fd0145d700dcc89ef902592a6ba98 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -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 char buffer[10];
9
10 while(1)
11 {
12 printf("thread_func\n");
13 sleep(1);
14 }
15 pthread_exit(0);
16}
17
18int main(int argc,char *argv[])
19{
20 pthread_attr_t attr;
21 pthread_t tid;
22 int s;
23
24 s = pthread_attr_init(&attr);
25 if (s != 0)
26 {
27 perror("pthread_attr_init error\n");
28 exit(-1);
29 }
30
31
32 s = pthread_create(&tid, &attr, thread_func, NULL);
33 if (s != 0)
34 {
35 perror("pthread_create error\n");
36 exit(-2);
37 }
38
39 s = pthread_join(tid, NULL);
40 if (s != 0)
41 {
42 perror("pthread_join error\n");
43 exit(-3);
44 }
45
46 return 0;
47}