Why use Monitor.Pulse?

Discussion in 'Microsoft C# .NET' started by Guest, Apr 13, 2007.

  1. Guest

    Guest Guest

    Hi,

    I'm new to threading, and am trying to understand monitor.pluse. I get the
    general idea, but what does this offer that simply using a semaphore does not
    offer? If you have two threads, couldn't you just immediately have one thread
    in the ciritical section and have the other try to enter. It will wait until
    the lock is handed back, and the lock could continue to be passed back and
    forth this way. The off thread will sleep until it's its turn. How is this
    different than "pulsing" a thread to a ready queue before handing a lock back?

    Thanks..

    -Ben
     
    Guest, Apr 13, 2007
    #1
    1. Advertisements

  2. Guest

    Technics Guest

    > I'm new to threading, and am trying to understand monitor.pluse. I get the
    > general idea, but what does this offer that simply using a semaphore does not
    > offer? If you have two threads, couldn't you just immediately have one thread
    > in the ciritical section and have the other try to enter. It will wait until
    > the lock is handed back, and the lock could continue to be passed back and
    > forth this way. The off thread will sleep until it's its turn. How is this
    > different than "pulsing" a thread to a ready queue before handing a lock back?



    Technically a monitor is an object that can handle more than ore
    resource at a time. Think about what would happen if a thread that is
    in its critical region needs a resource locked by another thread's
    semaphore and that second thread needs to enter in the critical region
    too. This would handle to a deadlock. A monitor should avoid this kind
    of problems.
     
    Technics, Apr 13, 2007
    #2
    1. Advertisements

  3. Guest

    Barry Kelly Guest

    Ben R. wrote:

    > I'm new to threading, and am trying to understand monitor.pluse. I get the
    > general idea, but what does this offer that simply using a semaphore does not
    > offer?


    A semaphore requires that you allocate a semaphore. Every object
    logically has a monitor associated with it.

    -- Barry

    --
    http://barrkel.blogspot.com/
     
    Barry Kelly, Apr 13, 2007
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DeveloperX

    Monitor.Pulse question

    DeveloperX, Nov 14, 2006, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    247
    DeveloperX
    Nov 14, 2006
  2. Rene

    Monitor Pulse/PulseAll/Wait question

    Rene, Feb 20, 2008, in forum: Microsoft C# .NET
    Replies:
    4
    Views:
    475
  3. AliRezaGoogle

    Conceptual Problem with Monitor.Enter and Monitor.Exit

    AliRezaGoogle, Jun 16, 2008, in forum: Microsoft C# .NET
    Replies:
    12
    Views:
    632
    AliRezaGoogle
    Jun 17, 2008
  4. Andrew Poelstra

    Set DTR pulse using System.IO.Ports.SerialPort

    Andrew Poelstra, Feb 21, 2010, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    3,707
    Andrew Poelstra
    Feb 21, 2010
  5. Tony Johansson

    why use Monitor.Enter...Monitor.Exit insted of lock(object9

    Tony Johansson, May 15, 2010, in forum: Microsoft C# .NET
    Replies:
    3
    Views:
    632
    Arne Vajhøj
    May 15, 2010
Loading...

Share This Page