1 #include <stdio.h>
2 #include <pthread.h>
3
4 #define NUM_THREADS 3
5
6 void *hello_thread(void *arg)
7 {
8 printf("Thread %d : Hello, World\n", arg);
9 return arg;
10 }
11
12 int main()
13 {
14 pthread_t tid[NUM_THREADS];
15 int i, status;
16
17 for(i = 0 ; i < NUM_THREADS ; i++)
18 {
19 status = pthread_create(&tid[i], NULL, hello_thread, (void*)i);
20 if(status != 0)
21 {
22 fprintf(stderr, "Create thread %d : %d", i, status);
23 exit(1);
24 }
25 }
26 pthread_exit(NULL);
27 }
28
이러한 스레드 프로그램을 컴파일 할 때는 옵션을 추가해주어야 한다.
gcc -o thread -lpthread thread.c
2 #include <pthread.h>
3
4 #define NUM_THREADS 3
5
6 void *hello_thread(void *arg)
7 {
8 printf("Thread %d : Hello, World\n", arg);
9 return arg;
10 }
11
12 int main()
13 {
14 pthread_t tid[NUM_THREADS];
15 int i, status;
16
17 for(i = 0 ; i < NUM_THREADS ; i++)
18 {
19 status = pthread_create(&tid[i], NULL, hello_thread, (void*)i);
20 if(status != 0)
21 {
22 fprintf(stderr, "Create thread %d : %d", i, status);
23 exit(1);
24 }
25 }
26 pthread_exit(NULL);
27 }
28
이러한 스레드 프로그램을 컴파일 할 때는 옵션을 추가해주어야 한다.
gcc -o thread -lpthread thread.c
댓글을 달아 주세요