I'm preparing for an exam regarding operating systems by doing past exams. It's mostly about Unix systems, the C programming language, and it mentions POSIX a lot, so it's probably best to ask this question here.
The problem is:
Give three disadvantages of simple spinlocks and/or semaphores. Explain how the respective other mechanism improves on the problem.
One of the 3 disadvantages given + explanation is this:
Semaphores require a system call even when the thread may proceed immediately. (0.5 P) Spinlocks on the other hand can be implemented completely in userspace and do not require syscalls. They are very efficient for short wait times. (0.5 P)
Why would semaphores require syscalls? Do they have to be in kernel space? Do they require execution of privileged instructions?
Both single-processor and multi-processor systems need to be considered.
Some historical context will make things clearer. Semaphores were originally part of the System V inter process communication package (System V IPC), before POSIX IPC was a thing. The names probably give you a clue as to where things are heading; the original use case was locks shared by cooperating processes. (I'm 99.99% percent sure IPC predated threads by quite a while.)
POSIX semaphores work with processes or threads, hence the OS involvement. Context is important here because the answer is clearly about the standard semaphore implementation, not the abstract concept of a semaphore.