3 ms·
Ehhhhh. The lowest level of synchronization is atomics + barriers. Semaphores are pretty high level IMO anyway. But not high enough level to be easier to use.
by dragontamer 4y ago
Ehhhhh.
The lowest level of synchronization is atomics + barriers. Semaphores are pretty high level IMO anyway. But not high enough level to be easier to use.
I'd say semaphores are more like the linked list of synchronization. Useful in some circumstances, way more popular 30 years ago and less popular today, still have plenty of legit uses but newer structures (Go's channels, pipes, eventfd, condition variables) have eaten away at the niche it carved out.
You can probably write all your multi threaded code in semaphores alone, proving their versatility. But it won't be the fastest or easiest to understand.
- Mikhail_Edoshin 4y agoI never understood why semaphore was called a primitive until I've read the original paper. Dijkstra called semaphore a primitive because the controlling part was a mere integer. A Boolean would be even more primitive but probably insufficient. But since a semaphore also has a queue of waiting processes it is of course a rather complex system.
- kazinator 4y agoIf you have that complex scheduling mechanism with queues and all, about the dumbest thing you can do is build a semaphore with it ... and then use the semaphore to build other primitives.