Reputation: 51445
how many pthreads mutex are usually available in a typical system?
Is having many pthreads mutex degrades performance?
Upvotes: 1
Views: 2861
Reputation: 215193
POSIX allows mutexes to be implemented as a system-level resource, but such an implementation would be considered extremely poor quality and I can't imagine anyone using it. In reality, on modern implementations (think Linux), the number of mutexes you can have is limited only by the virtual address space. (Actually you can have even more, up to the total size of physical memory/swap plus filesystem size, if you use mmap
and munmap
to map them in and out as needed.)
As for performance, on 32-bit glibc systems, unlocking robust mutexes is an O(n)
operation, where n
is the number of robust mutexes currently locked. This is due to using a singly-linked list where a doubly-linked one is needed; they ran out of space in their pthread_mutex_t
structure to fit both pointers. This issue only applies for robust mutexes, which are rarely used in practice, and only on 32-bit Linux/glibc. For all other mutex types, the number of mutexes has no impact on performance. The number of currently-contended-for mutexes, however, does have some impact on performance, but it's a complicated subject beyond the scope of a simple answer.
Upvotes: 3
Reputation: 213386
Several answers:
Upvotes: 1