Ticket #204: rwlock_deadlock_tight_loop.diff

File rwlock_deadlock_tight_loop.diff, 1.9 KB (added by KO Myung-Hun, 6 years ago)

Patch for deadock in pthread_rwlock_tryrdlock()/trywrlock() and a tight loop in thread_rwlock_rdlock()/wrlock()

  • rwlock.c

     
    9191  }
    9292
    9393  lock->mutex = 0;
     94  lock->cond = 0;
    9495  lock->num_active = 0;
    9596  //lock->exclusive_waiters = 0;
    9697  lock->num_shared_waiters = 0;
     
    99100  rc = pthread_mutex_init(&lock->mutex, NULL);
    100101  if (rc != 0) return rc;
    101102
     103  rc = pthread_cond_init(&lock->cond, NULL);
     104  if (rc != 0 ) {
     105      pthread_mutex_destroy(&lock->mutex);
     106
     107      return rc;
     108  }
     109
    102110  //lock->exclusive_waiters = mksem(0);
    103111  //if (lock->exclusive_waiters < 0) return errno;
    104112
     
    114122{
    115123  pthread_rwlock_t lock = *_lock;
    116124  if (!lock) return EINVAL;
     125  pthread_cond_destroy(&lock->cond);
    117126  pthread_mutex_destroy(&lock->mutex);
    118127  //if (close(lock->exclusive_waiters) < 0) return errno;
    119128  //if (close(lock->shared_waiters) < 0) return errno;
     
    224235      lock->num_active++;
    225236      break;
    226237    }
     238
     239    pthread_cond_wait(&lock->cond, &lock->mutex);
    227240  }
    228241
    229242  pthread_mutex_unlock(&lock->mutex);
     
    273286    //pthread_mutex_unlock(&lock->mutex);
    274287    //if (waitone(lock->exclusive_waiters, __abstime2timeout(abstime)) < 0) return errno;
    275288    //pthread_mutex_lock(&lock->mutex);
     289
     290    pthread_cond_wait(&lock->cond, &lock->mutex);
    276291  }
    277292
    278293  pthread_mutex_unlock(&lock->mutex);
     
    326341    }
    327342  }
    328343
     344  pthread_cond_broadcast(&lock->cond);
    329345  pthread_mutex_unlock(&lock->mutex);
    330346  return 0;
    331347}
  • pthread_private.h

     
    7878struct pthread_rwlock_t_
    7979{
    8080  pthread_mutex_t mutex;
     81  pthread_cond_t cond;
    8182  //handle_t shared_waiters;
    8283  //handle_t exclusive_waiters;
    8384  int num_shared_waiters;