Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int sum_stat_a = 0;
- static int sum_stat_b = 0;
- int aggregateStats(int stat_a, int stat_b) {
- pthread_mutex_lock(&mut);
- //wait for other thread to finish
- while (sum_stat_a == 0 && sum_stat_b == 0){
- pthread_cond_wait(&cond, &condlock);
- }
- pthread_mutex_unlock(&condlock);
- pthread_mutex_lock(&mut);
- sum_stat_a += stat_a;
- sum_stat_b += stat_b;
- return sum_stat_a + sum_stat_b;
- pthread_mutex_unlock(&mut);
- }
- void init(void)
- {
- pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
- pthread_mutex_t condlock;
- pthread_mutex_t mut;
- pthread_mutex_init(&condlock, NULL);
- pthread_mutex_init(&mut, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement