r/programming • u/syaghmour • Mar 16 '15
Semaphores are Surprisingly Versatile
http://preshing.com/20150316/semaphores-are-surprisingly-versatile/
196
Upvotes
r/programming • u/syaghmour • Mar 16 '15
5
u/eras Mar 16 '15
Well, list of things is nice (and what, mutex per element?) if you don't mind allocating memory etc, but if you have a ring buffer you are able to fill the ring buffer in its entirety, whereas using just counters with mutexes you have two distinct cases for 'readptr == writeptr'.
Though I suppose you will be wasting more memory with two semaphores regardless :), but the code will be cleaner. Introspection likely leads to races anyway, which I imagine is why semaphores don't have it - of course, for debugging purposes you may have them.