#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
pthread_mutex_t *mutexes;
void *thread_work(void *id)
{
long tid = (long)id;
while(some_condition)
{
pthread_mutex_lock(mutexes[0]);
}
}
If I allocate memory for mutexes
dynamically in the main
function, is it thread safe to use mutexes[0]
in threads? Are they going refer to the same mutexes or maybe create a copy for each thread?
I know it's basic knowledge but I got confused after reading some tutorials.