Locks Flashcards
Race condition
when who processes are trying to change the shared resource .
what is a critical section
The part of process which access a shared resource is known as a critical section.
can you use single flag to overcome race condition.
No you cannot.
Solutions to race condition
- run only one process in one CPU cycle
-use mutex locks
-semaphores
Peterson’s solution
here we have variables such as other, interested and turn.
this solution only works for two processes.
if one of the process is in the critical section then the other cannot enter the critical section.
Contention
this is seen in case of mutex or locks that is here only one process or thread is allowed to access the CS in a given time, while others are waiting for that process to leave the CS, but if the process in CS get’s killed then other processes will go into infinite wait this is known as contention.
conditional variable
here we have wait and notify.
here if one process is in CS then the other doesn’t go in a wait state that is it does not CPU cycles.
when P1 is done using the CS then it notifies other processes that it is done so which ever process needs it, it then can access it.
Semaphores
we use this when we have multiple instances of a resource in CS, so multiple threads can access it.