LWN.net Logo

Mutex is not a semaphore

Mutex is not a semaphore

Posted Mar 22, 2008 3:22 UTC (Sat) by willy (subscriber, #9762)
In reply to: Mutex is not a semaphore by ikm
Parent article: Generic semaphores

> I'd like to notice that one use of a semaphore is of a "fifo for
> token-like objects", that is, the one where the initial value is
> usually 0

The semaphore implementations (both current and new) do support this, but we have few if any
users of it currently in the kernel.  We have the 'completion' API which sort-of does what you
want (it's specialised for 'I am exiting now', but doesn't have to be used that way).

My motivation was really not to correct mutex vs semaphore usage but to add new features to
semaphores -- down_killable() and down_timeout() are the two I've added so far, each taking
very few additional lines of code.

I now suspect, having read over the completion code, that completions could be rewritten in
terms of my new semaphore implementation.  I'll look into it later.

Matthew Wilcox


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds