Re: Lock or semaphore, difference?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Dec 12, 4:39 am, "Alvin Bruney [ASP.NET MVP]" <vapor dan a t h u t
ma le dut cu m> wrote:
I believe your No should be a Yes. They are practically very different. As
you rightly pointed out, one is process wide only, the other is a kernel
object. Consequently, the underlying implementation is very differet - think
spin locks.

He asked whether they "execute exactly the same". There's a lot of
leeway in this phrase to answer the question either way. To me, the
important detail was the use of a named semaphore -- this is most
certainly *not* the same as using a lock, not even functionally,
because it requires that you only ever run one instance of your
program. That said, I'll gladly admit I answered "no" because I saw
the opportunity.

Funny thing is, I saw this quite recently as an actual bug. Making the
semaphore anonymous solved the problem. A classic case of not reading
the documentation, and the natural human urge to name things when you
have the opportunity, regardless of whether it's required.
.



Relevant Pages

  • Re: Lock or semaphore, difference?
    ... you rightly pointed out, one is process wide only, the other is a kernel ... the underlying implementation is very differet - ... Spin locks scare the bejesus out of me. ...
    (microsoft.public.dotnet.framework)
  • Re: spin locks
    ... Excerpt from O'Reilly's "Understanding The Linux Kernel, ... a semaphore could be very inefficient. ... time it takes to complete them, the other kernel control path could have ... multiprocessor operating systems use spin locks. ...
    (alt.os.linux)
  • Possible bug from kernel 2.6.22 and above
    ... We have a simple pthread program that measures the synchronization overheads for various synchronization mechanisms such as spin locks, barriers and so on. ... We have dual quad-core AMD opterons clusters running 2.6.23.8 kernel at this moment using Fedora Core 7 distribution. ... But the synchronization overhead actually decreases as the number of threads increases in the kernel 2.6.23.8. ...
    (Linux-Kernel)
  • Re: use of spinlocks
    ... > I wanted to know how kernel manages resources for multiprocessors. ... > far I know spin locks are used, ...
    (comp.os.linux.development.system)
  • panic: lock (sleep mutex) inp not locked
    ... polling and altq support for the sf driver and removed SMP ifdefs from ... Crashdump and debug kernel are available for further investigation. ... spin locks held: ...
    (freebsd-stable)