I am trying to make a realtime interprocess communication module.
In order to avoid unbounded priority inversion, deadlock, and chain blocking, I set PTHREAD_PRIO_PROTECT to each mutex.
below is how each mutex is initialized
pthread_mutexattr_init(&mutexattr);
if (pthread_mutexattr_setpshared(&mutexattr, PTHREAD_PROCESS_SHARED)) {
std::cout << "pthread_mutexattr_setpshared failed" << std::endl;
exit(-2);
}
if (pthread_mutexattr_setprotocol(&mutexattr, PTHREAD_PRIO_PROTECT)) {
std::cout << "Failed to set protocol" << std::endl;
exit(-2);
}
if (pthread_mutexattr_setprioceiling(&mutexattr, priority)) {//max priority among tasks that can lock
std::cout << "set priority ceiling failed" << std::endl;
exit(-2);
}
pthread_mutex_init(&mutex, &mutexattr);
There are exactly two mutexes(m1 & m2) There are more than two threads(t1, t2, ..., tn)
Now I intentionally gave a deadlock situation in which some thread locks m1 first and then m2, while other thread locks m2 first and then m1
And with priority ceiling protocol is set to each mutex, the deadlock situation isn't supposed to happen However, it still seems to happen.
Do you have any idea? Am I implementing it wrongly?
BTW each thread is set with SCHED_FIFO and some priority value 1 ~ 95