I do not understand some things. For example binary Semaphore and lock are the same? When using lock and when semaphore,or both?
-
Might be better suited for the Computer Science stack exchange. SO is more about specific programming questions, rather than theory and design practices. – Mark W Dec 28 '15 at 14:29
-
Possible duplicate http://stackoverflow.com/a/2332868/5656555 – fionaredmond Dec 28 '15 at 14:42
1 Answers
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).

- 606
- 4
- 11