semaphore and SMP question - Linux

This is a discussion on semaphore and SMP question - Linux ; I have thought only spin_lock can be used in SMP, as when I read doc. on the spin_lock, it was said spin_lock was designed to deal with SMP. But I didn't see SMP was mentioned for semaphore. Can semaphore be ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: semaphore and SMP question

  1. semaphore and SMP question

    I have thought only spin_lock can be used in SMP, as when I read doc.
    on the spin_lock, it was said spin_lock was designed to deal with SMP.
    But I didn't see SMP was mentioned for semaphore.

    Can semaphore be used with SMP? If not, will the semaphores used in the
    kernel cause problems in SMP? In driver/usb directory, some semaphores
    can be found. Or there are some special rules with it?

    I have learned that spin_lock is faster, and used in ISR, but thread
    that owns
    it can not sleep; semaphore is slow and can not used in ISR, but can
    sleep.

    Thanks!

    Yong


  2. Re: semaphore and SMP question

    On Wed, 12 Jul 2006 11:14:44 -0700, yozhang wrote:

    > Can semaphore be used with SMP? [...]


    > I have learned that spin_lock is faster, and used in ISR, but thread
    > that owns it can not sleep; semaphore is slow and can not used in ISR,
    > but can sleep.


    That description is roughly correct, but entirely orthogonal to
    the issues of SMP. Both spinlocks and mutexes (which replace
    semaphores) can be used for the purposes of SMP synchronization.

    -- Pete


  3. Re: semaphore and SMP question

    Golden rule to decide whether to use a semaphore or a spinlock is that
    if you are certain that ur thread is not going to sleep long, use
    Spinlock ( remeber it will waste CPU cyles though and decrease overall
    througput) Else use semaphore.

    Semaphore are used where sleep period is significant.

    shiva

    Pete Zaitcev wrote:
    > On Wed, 12 Jul 2006 11:14:44 -0700, yozhang wrote:
    >
    > > Can semaphore be used with SMP? [...]

    >
    > > I have learned that spin_lock is faster, and used in ISR, but thread
    > > that owns it can not sleep; semaphore is slow and can not used in ISR,
    > > but can sleep.

    >
    > That description is roughly correct, but entirely orthogonal to
    > the issues of SMP. Both spinlocks and mutexes (which replace
    > semaphores) can be used for the purposes of SMP synchronization.
    >
    > -- Pete



  4. Re: semaphore and SMP question

    Thanks for the replies.

    Yong
    shiva wrote:
    > Golden rule to decide whether to use a semaphore or a spinlock is that
    > if you are certain that ur thread is not going to sleep long, use
    > Spinlock ( remeber it will waste CPU cyles though and decrease overall
    > througput) Else use semaphore.
    >
    > Semaphore are used where sleep period is significant.
    >
    > shiva
    >
    > Pete Zaitcev wrote:
    > > On Wed, 12 Jul 2006 11:14:44 -0700, yozhang wrote:
    > >
    > > > Can semaphore be used with SMP? [...]

    > >
    > > > I have learned that spin_lock is faster, and used in ISR, but thread
    > > > that owns it can not sleep; semaphore is slow and can not used in ISR,
    > > > but can sleep.

    > >
    > > That description is roughly correct, but entirely orthogonal to
    > > the issues of SMP. Both spinlocks and mutexes (which replace
    > > semaphores) can be used for the purposes of SMP synchronization.
    > >
    > > -- Pete



+ Reply to Thread