I'm working on linux. In my code I'm trying to run a few threads ( lets say 2 for example) that are trying to lock a RECURSIVE mutex, but only one thread can access and lock the mutex while the second one gets an EBUSY error even after the first thread has unlocked it. I think it's because the mutex is PRIVET and not SHARED.
I'm trying to set the mutex to be both RECRUSIVE and SHARED like this:
void
MutexCreate(pthread_mutex_t* _m)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(_m, &attr);
}
(I do check for function errors - and all of them return 0)
Even if I try to make it a DEFAULT SHARED mutex by :
void
MutexCreate(pthread_mutex_t* _m)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
pthread_mutex_init(_m, &attr);
}
it still remains PRIVET.
Any ideas?