Reputation: 105
I do not understand some things. For example binary Semaphore and lock are the same? When using lock and when semaphore,or both?
Upvotes: 4
Views: 1428
Reputation: 616
The difference between a lock and a binary semaphore is only a apparent when there are multiple processes trying to access the same resource. A "process" is defined here as an instance of a program or application that may contain one or more threads.
Both allow only one thread to access a resource at a given time. However, locks can only limit access within a single process while binary semaphores can limit access across multiple processes.
Therefore, within a single process, the behavior of a lock and a binary semaphore are the same. Both allow only one thread to access a resource a given time.
Across multiple processes, the behavior is different. A binary semaphore will allow only one process to access a given resource at a time, but a lock will give multiple processes to access to a resource a time (but only a single thread in each process will have access at a given time).
Upvotes: 3