When I searched how I can use semaphores in C++11, I saw people often suggest that I make one out of a std::mutex
and a std::condition_variable
(this post for example). This made me think that semaphores are a higher-level abstraction than mutexes and condition variables.
However, after I took our operation system class, I now know that in the kernel, semaphores are usually the lowest-level of abstraction. Semaphores are implemented by disabling interrupts, and locks are essentially semaphores with value 1, while condition variables are implemented from ground up without using semaphores or locks. So it seems semaphores (at kernel-level) are not in anyway a higher-level abstraction than locks or condition variables.
So my question is, is my conclusion that "semaphores (in C++11) are a higher-level abstraction" just an artifact of the limitation of the standard library? Or is it a result of the difference between user-level and kernel-level synchronization?