Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Other then avoiding a syscall on an uncontended path they are not really similar. A benaphore is just a semaphore with an extra atomic counter in userspace to count waiters.

You can’t really use semaphores to implement things that can’t mutexes or semaphores so the overall utility is limited compare to futexes that you can use for condvars and other primitives too.



i mean you can use semaphores to implement condition variables, but it's extremely tricky to the point where you've got to be Mike Burrows in order to do it right [1] (in fact, that's how it's done in the nsync library, as a fallback when every faster option is unavailable).

[1] http://birrell.org/andrew/papers/ImplementingCVs.pdf


> i mean you can use semaphores

You absolutely can use semaphores for it, but the benefits of a benaphore would not work with when you build a condition variable with it. The wait on the CV would need to go through the kernel.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: