The frequent calls to pthread_mutex_lock( ) and pthread_mutex_unlock() would cause a performance degradation, and the program- mer would be very likely to make a mistake in the order of calls and cause a deadlock.
The solution is in some balanced grouping of the global variables and in having a mutex for each group.引自 Mutually Exclusive Locks (Mutexes)