You can only set a struct that way on initialization, so while
Code: Select all
pthread_mutex_t mymutex = { { 0, 0, 0, 0, 0, { 0 } } };
is valid,
Code: Select all
pthread_mutex_t mymutex;
mymutex = { { 0, 0, 0, 0, 0, { 0 } } };
is not.
A way around this limitation would be to do something like this:
Code: Select all
pthread_mutex_t mymutex;
pthread_mutex_t tmpMutex = { { 0, 0, 0, 0, 0, { 0 } } };
mymutex = tmpMutex;
but if you are, in fact, using a pthread mutex then you really shouldn't get into the habit of assigning the value of one pthread_mutex_t to another (probably won't hurt with the initializer value, but others could lead to some unfortunate and hard-to-debug problems). In that case, it's probably better to use pthread_mutex_init:
Code: Select all
pthread_mutex_t mymutex;
pthread_mutex_init(&mymutex,NULL);