[thread.sema.general] # 32 Concurrency support library [[thread]](./#thread) ## 32.8 Semaphore [[thread.sema]](thread.sema#general) ### 32.8.1 General [thread.sema.general] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10435) Semaphores are lightweight synchronization primitives used to constrain concurrent access to a shared resource[.](#1.sentence-1) They are widely used to implement other synchronization primitives and, whenever both are applicable, can be more efficient than condition variables[.](#1.sentence-2) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10441) A counting semaphore is a semaphore object that models a non-negative resource count[.](#2.sentence-1) A binary semaphore is a semaphore object that has only two states[.](#2.sentence-2) A binary semaphore should be more efficient than the default implementation of a counting semaphore with a unit resource count[.](#2.sentence-3)