it is a mystery to me why the codes worked before. anyway, is the function above equal to
for(int i = 0; i < 10; i ++)
{
pthread_mutex_init(&a[i], NULL);
}
I never use PTHREAD_MUTEX_INITIALIZER and do not know it can used this way for array. HOwever, my understanding is taht it can ONLY be used for static mutex and be initialized the first time the mutex get called, right?
pthread_mutex_t, at least in my implementation (POSIX defines it as an opaque type), is a struct containing several member variables that happen to want to be initialized to 0 in order to work properly. Your static array probably happens to be allocated in memory that is already initialized to zero, so it happens to work.
Nonetheless, to be safe, you should initialize the mutexes.
I just verified that my above code will not work. You need to do the for() loop as you wrote above instead.