I am writing an application that requires that certain activities for a given user are not stomped on by possibly competing threads. My entire user database is in memory and I was thinking of adding a pthread_rwlock_t
to the user data structure. I do not anticipate more than about 10 to 20 thousand users. At 56 bytes for the lock structure that's not a lot of RAM at all. My question is, is there a practical limitation to the number of actual rwlocks you can have in a process? Please note I am NOT talking about the number of threads that can get a lock, or the number of times a given thread can increment the lock counter. Rather, I am wondering if there is some underlying kernel or other resource that backs each individual lock that I may end up exhausting.
This is a quality-of-implementation issue: POSIX allows the initialisation of a rwlock to fail due to resource exhaustion. However, common Linux implementations, for example, don't require any per-lock resources other than the memory for the pthread_rwlock_t
itself.