In the below scenario how the priority of the task t1 will change when the locks are released, assuming Sem_Take() and Sem_Give() are lock and release method.
I understand that using priority ceiling protocol raises the priority of the task as soon as a resource is locked, but what happens when the lock is released.
void t1()//Initial priority 2
{
int a;
Sem_take(S1); //priority ceiling for S1 is 4
.
.
Sem_take(S2);//priority ceiling for S2 is 6
.
.
Sem_Give(S1);
.//What is the priority at this line?
.
Sem_Give(s2);
.//What is the priority at this line?
.
}
Also in the above scenario the semaphore lock and release are mismatched that is it erroneous but a program might mistakenly do that, then in this case how the PCP will work.
Priority ceiling was created to avoid priority inversion. A well implemented algorithm would always give each process the highest priority that is associated with each of the resources held by that process (in this case semaphores). So specifically regarding your code sample: after taking S1, the process priority will be raised to 4, then after taking S2 it will be raised again to 6. Upon releasing S1 priority is still 6 (S2 is still held). Upon releasing S2 it should revert back to priority == 2.