Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <pthread.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define num_loops 2000000
  5. void *functionC (void* ptr) ;
  6. pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER ;
  7.  
  8. int sum = 0 ;
  9. int main ()
  10. {
  11. int rc1 , rc2 ;
  12. pthread_t thread1 , thread2 ;
  13. int value1 = 1 ;
  14. int value2 = -1;
  15.  
  16. rc1 = pthread_create(&thread1, NULL , &functionC, (void*) value1);
  17. rc2 = pthread_create(&thread2, NULL , &functionC, (void*) value2);
  18.  
  19. pthread_join(thread1, NULL);
  20.  
  21. pthread_join(thread2, NULL);
  22. printf("counter value = %d\n", sum);
  23. exit(0);
  24.  
  25.  
  26. }
  27. void *functionC (void*ptr)
  28. {
  29.  
  30. int ctr = (int*)ptr;
  31. int i ;
  32. pthread_mutex_lock(&mutex1);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement