Advertisement
tei123

Untitled

Jan 24th, 2019
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2.     #include <pthread.h>
  3.     #include <unistd.h>
  4.     static void * sum_line(int nr_line);
  5.    
  6.     int Sum;
  7.     int A[4][4];
  8.    
  9.     int main() {
  10.     pthread_t tid;
  11.     Sum=0;
  12.     printf("\nOrig thread tid(%d) Sum=%d", pthread_self(), Sum);
  13.     pthread_create(&tid, NULL, &sum_line(0), NULL);
  14.     printf("\nChild thread was created tid(%d)", tid);
  15.     pthread_join(tid,NULL);
  16.     printf("\nOrig thread tid(%d)-->Child thread ended tid(%d) Sum=%d",pthread_self(), tid, Sum);
  17.     printf("\n");
  18.    
  19.     }
  20.    
  21.     static void * sum_line(int nr_line) {
  22.         int i;
  23.         for(i=0;i<4;i++) {
  24.             Sum=Sum+A[i];
  25.             printf("\nChild thread tid(%d), i=%d, Sum=%d",pthread_self(),i,Sum);
  26.             sleep(2);
  27.         }
  28.         printf("\nChild thread tid(%d)--> ending", pthread_self());
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement