Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pthread.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define num_loops 2000000
- void *functionC (void* ptr) ;
- pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER ;
- int sum = 0 ;
- int main ()
- {
- int rc1 , rc2 ;
- pthread_t thread1 , thread2 ;
- int value1 = 1 ;
- int value2 = -1;
- rc1 = pthread_create(&thread1, NULL , &functionC, (void*) value1);
- rc2 = pthread_create(&thread2, NULL , &functionC, (void*) value2);
- pthread_join(thread1, NULL);
- pthread_join(thread2, NULL);
- printf("counter value = %d\n", sum);
- exit(0);
- }
- void *functionC (void*ptr)
- {
- int ctr = (int*)ptr;
- int i ;
- pthread_mutex_lock(&mutex1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement