Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation



On Fri, 2005-12-16 at 13:41 -0800, Linus Torvalds wrote:
>
> > > No one. It's not really a mutex, but a completion.
> >
> > Well, then let us use a completion and not some semantically wrong
> > workaround
>
> It is _not_ wrong to have a semaphore start out in locked state.
>
> For example, it makes perfect sense if the data structures that the
> semaphore needs need initialization. The way you _should_ handle that is
> to make the semaphore come up as locked, and the data structures in some
> "don't matter" state, and then the thing that initializes stuff can do so
> properly and then release the semaphore.
>
> Yes, in some cases such a locked semaphore is only used once, and ends up
> being a "completion", but that doesn't invalidate the fact that this is
> a perfectly fine way to handle a real issue.

Well, in case of a semaphore it is a semantically correct use case. In
case of of a mutex it is not.

Gerd was talking about a mutex. The fact that a mutex is implemented on
top (or on actually the same) mechanism as a semaphore - for what ever
reason - does not change the semantical difference between semaphores
and mutexes.

tglx


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
    ... > a mutex was a sensible implementation tradeoff. ... are really counting semaphores, ... >> acceptable patch that introduces a separate data structure. ... > general semaphore, because a mutex has stronger invariants. ...
    (Linux-Kernel)
  • Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
    ... >> A counting semaphore is NOT a perfectly fine mutex, ... >> People are indeed unhappy with the naming, ...
    (Linux-Kernel)
  • [patch 00/15] Generic Mutex Subsystem
    ... generic mutex subsystem that we have in the -rt kernel, ... 'simple mutex' code recently posted by David Howells.) ... 'struct mutex' is 16 bytes. ... than the semaphore based kernel, _and_ it also had 2.8 times less CPU ...
    (Linux-Kernel)
  • Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
    ... I thought you were considering naming unhappiness to be a reason ... _for_ the mutex change. ... a real double aquire, and not a race due to lock ordering) easy to see, ... a hung semaphore isn't exactly hard to debug). ...
    (Linux-Kernel)
  • Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
    ... > Outside of the arch directories, yes; but I don't know that I've made the ... I'm in the crowd that thinks that the mutex downs and ups should be ... that should be a semaphore. ... > I've attempted to review everything in 2.6.15-rc5 outside of most of the archs. ...
    (Linux-Kernel)