Graph(fork, join) sample code
This commit is contained in:
34
Practice_06/graph01.c
Normal file
34
Practice_06/graph01.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
int x = 5, y = 3, z = 7;
|
||||
int a, b, c, w;
|
||||
|
||||
void* task1(void* arg){
|
||||
a = x + y;
|
||||
printf("Task1 : a = %d\n", a);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* task2(void* arg){
|
||||
b = z + 1;
|
||||
printf("Task2 : b = %d\n", b);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(){
|
||||
pthread_t t1, t2;
|
||||
|
||||
pthread_create(&t1, NULL, task1, NULL);
|
||||
pthread_create(&t2, NULL, task2, NULL);
|
||||
|
||||
pthread_join(t1, NULL);
|
||||
pthread_join(t2, NULL);
|
||||
|
||||
c = a - b;
|
||||
w = c + 1;
|
||||
printf("c = %d\n", c);
|
||||
printf("w = %d\n", w);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user