C - Mutex attributes -
can create , use 1 mutex attribute initialize multiple recursive mutexes? or have create 1 mutex attribute each mutex want create? following code correct?
int err; int bufferlength = 10; pthread_mutexattr_t recursiveattr; pthread_mutex_t mutexes[bufferlength]; for(int index = 0; index < bufferlength; index++){ err = pthread_mutex_init(&mutexes[i], &recursiveattr); if(err != 0){ perror("error initializing mutex"); } }
you can use same attribute object multiple mutexes.
note however, pthread_mutexattr_t
object you're using must initialized itself. initialize pthread_mutexattr_t
must use pthread_mutexattr_init
(and eventually, pthread_mutexattr_destroy
), both of should done once. current code makes no such calls, , should compliant.
Comments
Post a Comment