From bb465e1a48c09965d9017c1657f821df20475c4c Mon Sep 17 00:00:00 2001 From: foxliver Date: Thu, 25 Sep 2025 16:30:00 +0900 Subject: [PATCH] Graph(fork, join) sample code --- Practice_06/graph01.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Practice_06/graph01.c diff --git a/Practice_06/graph01.c b/Practice_06/graph01.c new file mode 100644 index 0000000..d2aa9e0 --- /dev/null +++ b/Practice_06/graph01.c @@ -0,0 +1,34 @@ +#include +#include + +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; +} \ No newline at end of file