I would like to create a dynamic malloced pthread_mutex array that will grow over time (adding additional mutexes). My question is whether they will work if the array is moved using realloc (). My concern is that pthread_mutex_init () might somehow tweak the internal information, which depends on the mutex address at that moment.
To be more specific, here is a fragment of a toy that shows the problem:
pthread_mutex_t *my_mutexes = (pthread_mutex_t *) malloc (sizeof(pthread_mutex_t)); pthread_mutex_init (my_mutexes, NULL); my_mutexes = (pthread_mutex_t *) realloc (my_mutexes, 2*sizeof(pthread_mutex_t));
I suppose that the answer in all such cases is "if this is not explicitly permitted, do not accept", but I wanted to get the advice of the sage here. If the conclusion is not for this, then I wonder how, in the general case, I could create a growing list of mutexes.
source share