Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. void* calc(void* arg)
  2. {
  3.     long* x = data.a;
  4.     long mysum = 0;
  5.     long i, lock;
  6.     long start, end;
  7.  
  8.  
  9.  
  10.     pthread_mutex_lock(&mutex2);
  11.  
  12.     start = x[*(int*)arg * LENGTH];
  13.     end = start + LENGTH;
  14.  
  15.     pthread_mutex_unlock(&mutex2);
  16.  
  17.  
  18.     for (i = start;i<end;i++){
  19.         mysum += x[i];
  20.     }
  21.  
  22.     pthread_mutex_lock(&mutex);
  23.     data.sum += mysum;
  24.     pthread_mutex_unlock(&mutex);
  25.  
  26.     pthread_exit((void*) 0);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement