What is the difference between Counting and binary semaphore.
What I have seen somewhere is that both can control N number of processes which have requested for a resource. Both have taken and Free states.
Is there any restriction on how many Resources a Binary semaphore and Counting semaphore can protect?
Both allow only One process to use a resource at a time...
Is there any other difference? Are the above mentioned properties correct?
Actually, both types are used to synchronize access to a shared resource, whether the entity which is trying to access is a process or even a thread.
The difference is as follows:
Binary semaphores are binary, they can have two values only; one to represent that a process/thread is in the critical section(code that access the shared resource) and others should wait, the other indicating the critical section is free.
On the other hand, counting semaphores take more than two values, they can have any value you want. The max value X they take allows X process/threads to access the shared resource simultaneously.
For further information, take a look at this link.
http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:semaphores_mutexes
EDIT
The max value that a counting semaphore can take is the the number of processes you want to allow into the critical section at the same time.
Again, you might have a case where you want exclusion over a certain resource, yet you know this resource can be accessed by a max number of processes (say X), so you set a counting semaphore with the value X.
This would allow the X processes to access that resource at the same time; yet the process X+1 would have to wait till one of the processes in the critical section gets out.