News for hackers. Stuff that matters.
Re:Semaphores are surprisingly versatile by pslam on Monday March 16, 2015 @04:20PM (#9214100)
Thanks for posting this. I'm often surprised how few people know that almost all synchronization primitives can be implemented with each other. They are effectively equivalent.

However, as you say, some end up being hideously complicated. Some are "closer to the metal" than others - both in terms of the actual instruction set implementation, and kernel mechanisms used.

I've never been a fan of semaphores, because when used with count>1, they tend to be duplicating some other information in the system, which is easy to get out of sync. When used with just count 0 or 1, it's more intuitive (and closer to underlying implementation) to just use a mutex. And as you point out, the various mutex incarnations usually have an easier time of tracking ownership and debugging, by their nature.

Re:Semaphores are surprisingly versatile by kazinator on Monday March 16, 2015 @04:43PM (#9214263)
> ... almost all synchronization primitives can be implemented with each other

Not to mention that any partial recursive function can be computed by a machine which can move along an unlimited tape, reading or writing a symbol, according to a handful of rules. :)

> And as you point out, the various mutex incarnations usually have an easier time of tracking ownership and debugging

Ownership, whether or not the owning thread died, deadlock detection, recursion detection ... priority inversion handling like priority inheritance ...