← cproj

pthread - create thread

294913768bcef0ad1ecdf2fb33dcf58bc09bcb76 · ovidiucs · Dec 5, 2019 07:52

+12 −5 · 1 file changed

  • graph/db/pthreads/pthread_example.c +12 −5
diff --git a/graph/db/pthreads/pthread_example.c b/graph/db/pthreads/pthread_example.c
index 2507fd3..2fa691e 100644
--- a/graph/db/pthreads/pthread_example.c
+++ b/graph/db/pthreads/pthread_example.c
@@ -1,24 +1,31 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <pthread.h>
-
-void foo(){
+// https://youtu.be/uA8X5zNOGw8
+void *foo(void *arg){
   while(1) {
   fprintf(stdout,"My Turn\n");
   sleep(1);
   }
+  return NULL;
 }
 
 void bar(){
   while(1) {
-  fprintf(stdout,"Yout Turn\n");
+  fprintf(stdout,"Your Turn\n");
   sleep(1);
   }
 
 }
 int main (int argc, char** argv) {
+  //1. Create thread.
+  pthread_t newthread;
+
+  //2. args, pthread_t address, NUL
+  pthread_create(&newthread, NULL,foo, NULL);
+
 
-    foo();
-    bar();
+//  foo();
+   bar();
    return 0;
 }