0
我的服務器中的線程之間有很多共享數據。如果我使用一個pthread_rwlock,則多線程停止。我使用rwlocks數組:如何在Linux 2.6中使用最大數量pthreads_rwlock
#define DIR_LOCK_COUNT 32
pthread_rwlock_t dir_mutex[DIR_LOCK_COUNT];
...
# into main thread initialize pthread_rwlock
for(i=0; i < DIR_LOCK_COUNT; i++){
if(pthread_rwlock_init(&dir_mutex[i], NULL) != 0) {
syslog(LOG_ERR, "can't initialize rwlock %i", i);
return ERR;
}
}
...
# in the worker thread
int num = user_id % DIR_LOCK_COUNT;
pthread_rwlock_rdlock(&dir_mutex[num]);
struct dir *dir_trash = dict_search((dict*)user->dirs, &dir_trash_id);
pthread_rwlock_unlock(&dir_mutex[num]);
我有35K用戶和16個線程池的數組。我可以使用pthread_rwlock的維度是1024還是更多?