In: Computer Science
What is the main difference between semaphore and a CV? A semaphore and a lock?
Answer = Both Semaphores and Locks are used to lock the resource to one process to secure system from deadlock condition. Here the main difference between both is that, "Locks have only two states (0 & 1), where 0 is stands for locked resource and 1 is stands for unlocked resources. In locks only one thread can enter in critical section at a time."
But in Semaphores we have multiples states (0,1,2,3,4,...), where 0 is for locked resources and (1,2,3,4,....) is for unlocked resources. here multiple threads can go in critical section, but they can only access unlocked resources.
If one resources is accessed by one processor then that resource is gone in locked condition, means no one can access that resource until processor releases that resource or resource again come in unlocked state.
when a processor uses any resource then it is called in critical section. when a proceesor uses a resource then it called "acquire()" and if it releases a resource then it called "release()".