From 466b63c681be24f342d4dc8c466ccc7f45584256 Mon Sep 17 00:00:00 2001
From: antux18 <antux18@gmail.com>
Date: Mon, 15 Apr 2024 15:44:16 +0200
Subject: [PATCH] Suite t3.

---
 ex2/T3.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/ex2/T3.c b/ex2/T3.c
index 0d03106..ea0ad41 100644
--- a/ex2/T3.c
+++ b/ex2/T3.c
@@ -5,21 +5,22 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-void* runner(void* pid) {
-    printf("My TID is: %ld\nMy PID is: %d\n", pthread_self(), *((int*) pid));
+void* runner(void* arg) {
+    printf("My TID is: %ld, my PID is: %d\n", pthread_self(), getpid());
     pthread_exit(0);
 }
 
-pthread_t thread_gen(int* pid) {
+pthread_t thread_gen() {
     pthread_t tid;
     pthread_attr_t attr;
     pthread_attr_init(&attr);
-    pthread_create(&tid, &attr, runner, (void*) pid);
+    pthread_create(&tid, &attr, runner, NULL);
     return tid;
 }
 
 int main() {
     int cpid1, cpid2;
+    // Fork 1:
     switch (cpid1 = fork()) {
         case -1 :
             perror("error");
@@ -27,8 +28,8 @@ int main() {
         case 0 :
             // Child process:
             pthread_t tid1, tid2;
-            tid1 = thread_gen(&cpid1);
-            tid2 = thread_gen(&cpid1);
+            tid1 = thread_gen();
+            tid2 = thread_gen();
             pthread_join(tid1, NULL);
             pthread_join(tid2, NULL);
             exit(0);
@@ -39,6 +40,7 @@ int main() {
                 perror("error");
             }
     }
+    // Fork 2:
     switch (cpid2 = fork()) {
         case -1 :
             perror("error");
@@ -46,9 +48,9 @@ int main() {
         case 0 :
             // Child process:
             pthread_t tid1, tid2, tid3;
-            tid1 = thread_gen(&cpid2);
-            tid2 = thread_gen(&cpid2);
-            tid3 = thread_gen(&cpid2);
+            tid1 = thread_gen();
+            tid2 = thread_gen();
+            tid3 = thread_gen();
             pthread_join(tid1, NULL);
             pthread_join(tid2, NULL);
             pthread_join(tid3, NULL);
-- 
GitLab