Thread.Sleep...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news.microsoft.com

    #16
    Re: Thread.Sleep...

    When I said spinwait i meant a Thread.Sleep(Fr equency); not per iteration
    as in SpinWait(N);

    Maybe a bad choice of terminology.

    "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
    news:MPG.1a0c29 0011216dcc9899b e@msnews.micros oft.com...[color=blue]
    > news.microsoft. com <discussion@dis cussion.microso ft.com> wrote:[color=green]
    > > I used the AutoResetEvent. Set to signal the worker thread and
    > > AutoResetEvent. WaitOne() to put it to sleep.
    > >
    > > I dont see the need for Monitor.Wait and Monitor.Pulse as the shared[/color][/color]
    item is[color=blue][color=green]
    > > already using the synchronised wrapper.[/color]
    >
    > You're certainly only like to need *either* AutoResetEvent *or*
    > Monitor.Wait/Pulse, but I don't see why using a synchronised wrapper
    > would knock Monitor.Wait/Pulse out of the equation.
    >[color=green]
    > > I still have a spin wait so its working on the items at a good pace and[/color][/color]
    not[color=blue][color=green]
    > > burning the CPU from other more important threads.[/color]
    >
    > I don't think a spin wait is a particularly good way of doing that
    > though - why not just sleep briefly? IIRC, the purpose of spin waits is
    > to wait *without* yielding to another thread, if you have a good reason
    > to believe that the reason you're unwilling to do more work is about to
    > be removed, as it were.
    >[color=green]
    > > Is it possible to prioritise threads?[/color]
    >
    > Sort of - have a look at the Thread.Priority property. Note that it
    > doesn't have to be honoured.
    >
    > --
    > Jon Skeet - <skeet@pobox.co m>
    > http://www.pobox.com/~skeet
    > If replying to the group, please do not mail me too[/color]


    Comment

    • news.microsoft.com

      #17
      Re: Thread.Sleep...

      AutoResetEvent Just made more sense to me than Monitor.Wait and .Pulse, both
      would be doing the same job here so what are the benifits of
      Monitor.Wait/Pulse over AutoResetEvent?


      "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in message
      news:uQRTZb4nDH A.2652@TK2MSFTN GP09.phx.gbl...[color=blue]
      > When I said spinwait i meant a Thread.Sleep(Fr equency); not per iteration
      > as in SpinWait(N);
      >
      > Maybe a bad choice of terminology.
      >
      > "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      > news:MPG.1a0c29 0011216dcc9899b e@msnews.micros oft.com...[color=green]
      > > news.microsoft. com <discussion@dis cussion.microso ft.com> wrote:[color=darkred]
      > > > I used the AutoResetEvent. Set to signal the worker thread and
      > > > AutoResetEvent. WaitOne() to put it to sleep.
      > > >
      > > > I dont see the need for Monitor.Wait and Monitor.Pulse as the shared[/color][/color]
      > item is[color=green][color=darkred]
      > > > already using the synchronised wrapper.[/color]
      > >
      > > You're certainly only like to need *either* AutoResetEvent *or*
      > > Monitor.Wait/Pulse, but I don't see why using a synchronised wrapper
      > > would knock Monitor.Wait/Pulse out of the equation.
      > >[color=darkred]
      > > > I still have a spin wait so its working on the items at a good pace[/color][/color][/color]
      and[color=blue]
      > not[color=green][color=darkred]
      > > > burning the CPU from other more important threads.[/color]
      > >
      > > I don't think a spin wait is a particularly good way of doing that
      > > though - why not just sleep briefly? IIRC, the purpose of spin waits is
      > > to wait *without* yielding to another thread, if you have a good reason
      > > to believe that the reason you're unwilling to do more work is about to
      > > be removed, as it were.
      > >[color=darkred]
      > > > Is it possible to prioritise threads?[/color]
      > >
      > > Sort of - have a look at the Thread.Priority property. Note that it
      > > doesn't have to be honoured.
      > >
      > > --
      > > Jon Skeet - <skeet@pobox.co m>
      > > http://www.pobox.com/~skeet
      > > If replying to the group, please do not mail me too[/color]
      >
      >[/color]


      Comment

      • Jon Skeet [C# MVP]

        #18
        Re: Thread.Sleep...

        news.microsoft. com <discussion@dis cussion.microso ft.com> wrote:
        [color=blue]
        > When I said spinwait i meant a Thread.Sleep(Fr equency); not per iteration
        > as in SpinWait(N);[/color]

        Ah, right. A spin wait is very different - it's a way of saying, "Keep
        yourself busy, but don't actually do anything useful, just for a little
        bit." Thread.Sleep is fine.
        [color=blue]
        > AutoResetEvent Just made more sense to me than Monitor.Wait and .Pulse, both
        > would be doing the same job here so what are the benifits of
        > Monitor.Wait/Pulse over AutoResetEvent?[/color]

        I don't know that there are any, other than that Monitor.Wait/Pulse are
        less .NET/Windows-specific concepts. They act in slightly different
        ways, but I don't know enough detail about what you want to know which
        would be better.

        I tend to prefer Monitor.Wait/Pulse/PulseAll as they're very similar to
        Java's Object.Wait/Notify/NotifyAll. Just personal preference, really.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • news.microsoft.com

          #19
          Re: Thread.Sleep...

          I think most people are familiar with the concept of AutoResetEvents more
          than monitor pulse and wait so its even more readable. Both achieve the
          same effect as far as I can see except Monitor takes a lock on the object
          and autosetevent does not. Its just an event really. Since the item is
          already synchronised I was more concerned about taking another lock on that
          object with Monitor.Wait/Pulse.



          "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
          news:MPG.1a0c32 99e9a771c29899c 0@msnews.micros oft.com...[color=blue]
          > news.microsoft. com <discussion@dis cussion.microso ft.com> wrote:
          >[color=green]
          > > When I said spinwait i meant a Thread.Sleep(Fr equency); not per[/color][/color]
          iteration[color=blue][color=green]
          > > as in SpinWait(N);[/color]
          >
          > Ah, right. A spin wait is very different - it's a way of saying, "Keep
          > yourself busy, but don't actually do anything useful, just for a little
          > bit." Thread.Sleep is fine.
          >[color=green]
          > > AutoResetEvent Just made more sense to me than Monitor.Wait and .Pulse,[/color][/color]
          both[color=blue][color=green]
          > > would be doing the same job here so what are the benifits of
          > > Monitor.Wait/Pulse over AutoResetEvent?[/color]
          >
          > I don't know that there are any, other than that Monitor.Wait/Pulse are
          > less .NET/Windows-specific concepts. They act in slightly different
          > ways, but I don't know enough detail about what you want to know which
          > would be better.
          >
          > I tend to prefer Monitor.Wait/Pulse/PulseAll as they're very similar to
          > Java's Object.Wait/Notify/NotifyAll. Just personal preference, really.
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          • Jon Skeet [C# MVP]

            #20
            Re: Thread.Sleep...

            news.microsoft. com <discussion@dis cussion.microso ft.com> wrote:[color=blue]
            > I think most people are familiar with the concept of AutoResetEvents more
            > than monitor pulse and wait so its even more readable.[/color]

            That really depends on their background. If they're Java programmers
            they'll be more familiar with monitors and waiting/notifying them. If
            they're Win32 programmers they're probably more familiar with
            AutoResetEvents .
            [color=blue]
            > Both achieve the
            > same effect as far as I can see except Monitor takes a lock on the object
            > and autosetevent does not. Its just an event really. Since the item is
            > already synchronised I was more concerned about taking another lock on that
            > object with Monitor.Wait/Pulse.[/color]

            You don't have to use that particular object though - I usually
            advocate using a separate object specifically for locking/waiting etc.
            The cost of taking out a lock is pretty small, especially when
            uncontested.

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • news.microsoft.com

              #21
              Re: Thread.Sleep...

              Normally for using collections one uses the provided .SynRoot property thats
              there for that task. If you look at the examples for IEnumerable on
              collecitons thats what it uses. collectionObj.S ynRoot

              Still, I like to keep locks to a minimum and I dont see a need for a lock
              there on an already synchronized object so AutoResetEvents seemed to me to
              be more appropriate.

              Being a win32 coder , AutoResetEvents makes more sense to me as you point
              out.

              "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
              news:MPG.1a0c3c 846ac29af09899c 4@msnews.micros oft.com...[color=blue]
              > news.microsoft. com <discussion@dis cussion.microso ft.com> wrote:[color=green]
              > > I think most people are familiar with the concept of AutoResetEvents[/color][/color]
              more[color=blue][color=green]
              > > than monitor pulse and wait so its even more readable.[/color]
              >
              > That really depends on their background. If they're Java programmers
              > they'll be more familiar with monitors and waiting/notifying them. If
              > they're Win32 programmers they're probably more familiar with
              > AutoResetEvents .
              >[color=green]
              > > Both achieve the
              > > same effect as far as I can see except Monitor takes a lock on the[/color][/color]
              object[color=blue][color=green]
              > > and autosetevent does not. Its just an event really. Since the item is
              > > already synchronised I was more concerned about taking another lock on[/color][/color]
              that[color=blue][color=green]
              > > object with Monitor.Wait/Pulse.[/color]
              >
              > You don't have to use that particular object though - I usually
              > advocate using a separate object specifically for locking/waiting etc.
              > The cost of taking out a lock is pretty small, especially when
              > uncontested.
              >
              > --
              > Jon Skeet - <skeet@pobox.co m>
              > http://www.pobox.com/~skeet
              > If replying to the group, please do not mail me too[/color]


              Comment

              • Curious

                #22
                Re: Thread.Sleep...


                To Alvin.

                What's up with u dude - are you just a part-time ass or what? I
                noticed ur stupid post towards someone who asked a question regarding
                NGEN in one of the other .NET groups, as well as the rubbish ur
                posting to Jon Skeet in this thread.

                If you have something funny to say, then say it. If you have sod all
                useful to say - look into a mirror and tell it to the only person who
                cares.

                I've seen other posts by you where you have actually helped a lot of
                people, why do you then insist on posting crap at other times? There's
                always one I guess.......

                Comment

                • Jon Skeet [C# MVP]

                  #23
                  Re: Thread.Sleep...

                  news.microsoft. com <discussion@dis cussion.microso ft.com> wrote:[color=blue]
                  > Normally for using collections one uses the provided .SynRoot property thats
                  > there for that task. If you look at the examples for IEnumerable on
                  > collecitons thats what it uses. collectionObj.S ynRoot[/color]

                  Yes, SyncRoot is fine for that purpose, but it's often nice to have
                  separate monitors specifically for thread waiting/notification. It just
                  makes life a bit easier to understand (IMO) and threading is a very
                  hard thing to get right to start with.
                  [color=blue]
                  > Still, I like to keep locks to a minimum and I dont see a need for a lock
                  > there on an already synchronized object so AutoResetEvents seemed to me to
                  > be more appropriate.
                  >
                  > Being a win32 coder , AutoResetEvents makes more sense to me as you point
                  > out.[/color]

                  You should be aware that AutoResetEvents almost certainly use their own
                  locks internally - I'd be very surprised if they were actually
                  significantly more efficient than using Monitor.Wait/Pulse. I'm not
                  saying you shouldn't use them - it's a matter of personal preference,
                  as I've said, and your last reason makes a lot of sense, but I wouldn't
                  focus too much on not having many locks. Making sure that you only lock
                  what you need to is more important, and that usually involves having
                  *more* locks available, to make each one finer-grained.

                  --
                  Jon Skeet - <skeet@pobox.co m>
                  Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                  If replying to the group, please do not mail me too

                  Comment

                  • Alvin Bruney

                    #24
                    Re: Thread.Sleep...

                    NGEN? Can you post this so called thread so I can take a look at it.
                    [color=blue]
                    > NGEN in one of the other .NET groups, as well as the rubbish ur
                    > posting to Jon Skeet in this thread.[/color]

                    What gives you the right to jump in here and declare it was rubbish? I have
                    solid reasons for posting a question like this. May be you should ask before
                    taking a shot eh?

                    My reason for posting this
                    [color=blue][color=green]
                    >> Again I ask: why do you want to know?[/color]
                    >it is just soooo discouraging, that's all.[/color]

                    was because I am feeling rather inadequate with my thread knowledge. I was
                    simply wanting to know if I needed to keep working in the pursuit of
                    increasing this knowledge or whether I should give it up and do something
                    else with my life. As he said, it took him a while to get there. I'm not
                    there yet. That is why it is discouraging to me. I wasn't going to reply to
                    your bullshit because I didn't think I was being a half ass. You could have
                    just asked instead of jumping the gun.

                    And by the way, an individual calling himself Jack Mayoff has been spoofing
                    my email account (and others by the way) replying to threads in my name. I
                    haven't caught all his attempts but you may be referring to one of his. I
                    wont give you the benefit of the doubt either. In short, if you follow my
                    post, it is rather easy to differentiate between me and a wanna be. But then
                    again, you couldn't get this last one so go figure.

                    shall we say an apology is in order? preach, do you think i was being a half
                    ass?
                    --


                    -----------
                    Got TidBits?
                    Get it here: www.networkip.net/tidbits
                    <Curious> wrote in message news:3fa22f7d.8 1469750@news.mi crosoft.com...[color=blue]
                    >
                    > To Alvin.
                    >
                    > What's up with u dude - are you just a part-time ass or what? I
                    > noticed ur stupid post towards someone who asked a question regarding
                    > NGEN in one of the other .NET groups, as well as the rubbish ur
                    > posting to Jon Skeet in this thread.
                    >
                    > If you have something funny to say, then say it. If you have sod all
                    > useful to say - look into a mirror and tell it to the only person who
                    > cares.
                    >
                    > I've seen other posts by you where you have actually helped a lot of
                    > people, why do you then insist on posting crap at other times? There's
                    > always one I guess.......[/color]


                    Comment

                    • news.microsoft.com

                      #25
                      Re: Thread.Sleep...


                      "Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote in
                      message news:elulv08nDH A.360@TK2MSFTNG P12.phx.gbl...[color=blue]
                      > NGEN? Can you post this so called thread so I can take a look at it.
                      >[color=green]
                      > > NGEN in one of the other .NET groups, as well as the rubbish ur
                      > > posting to Jon Skeet in this thread.[/color]
                      >
                      > What gives you the right to jump in here and declare it was rubbish? I[/color]
                      have[color=blue]
                      > solid reasons for posting a question like this. May be you should ask[/color]
                      before[color=blue]
                      > taking a shot eh?
                      >[/color]


                      I have solid crap in my toilet.


                      [color=blue]
                      > My reason for posting this
                      >[color=green][color=darkred]
                      > >> Again I ask: why do you want to know?[/color]
                      > >it is just soooo discouraging, that's all.[/color]
                      >
                      > was because I am feeling rather inadequate with my thread knowledge. I was
                      > simply wanting to know if I needed to keep working in the pursuit of
                      > increasing this knowledge or whether I should give it up and do something
                      > else with my life. As he said, it took him a while to get there. I'm not
                      > there yet. That is why it is discouraging to me. I wasn't going to reply[/color]
                      to[color=blue]
                      > your bullshit because I didn't think I was being a half ass. You could[/color]
                      have[color=blue]
                      > just asked instead of jumping the gun.
                      >
                      > And by the way, an individual calling himself Jack Mayoff has been[/color]
                      spoofing[color=blue]
                      > my email account (and others by the way) replying to threads in my name. I
                      > haven't caught all his attempts but you may be referring to one of his. I
                      > wont give you the benefit of the doubt either. In short, if you follow my
                      > post, it is rather easy to differentiate between me and a wanna be. But[/color]
                      then[color=blue]
                      > again, you couldn't get this last one so go figure.
                      >
                      > shall we say an apology is in order? preach, do you think i was being a[/color]
                      half[color=blue]
                      > ass?
                      > --
                      >[/color]

                      No I don't think you were being a "half ass" I think you area a "complete
                      ass".



                      [color=blue]
                      > -----------
                      > Got TidBits?
                      > Get it here: www.networkip.net/tidbits
                      > <Curious> wrote in message news:3fa22f7d.8 1469750@news.mi crosoft.com...[color=green]
                      > >
                      > > To Alvin.
                      > >
                      > > What's up with u dude - are you just a part-time ass or what? I
                      > > noticed ur stupid post towards someone who asked a question regarding
                      > > NGEN in one of the other .NET groups, as well as the rubbish ur
                      > > posting to Jon Skeet in this thread.
                      > >
                      > > If you have something funny to say, then say it. If you have sod all
                      > > useful to say - look into a mirror and tell it to the only person who
                      > > cares.
                      > >
                      > > I've seen other posts by you where you have actually helped a lot of
                      > > people, why do you then insist on posting crap at other times? There's
                      > > always one I guess.......[/color]
                      >
                      >[/color]


                      Comment

                      • Curious

                        #26
                        Re: Thread.Sleep...


                        Yo.

                        Ahhh, well in that case it seems that indeed I was in the wrong. I
                        guess it was one of those days and I needed to get some steam out.

                        Having read some of your earlier posts and then reading "your" reply
                        to:

                        NGEN microsoft system dlls? by Bob Whiton in
                        microsoft.publi c.dotnet.perfor mance

                        I thought hang on, that's a bit out of order.

                        Again, appologies for jumping the gun there - never meant to upset you
                        in any way. I would feel bad if I did annoy you.

                        All the best dude.

                        'The mistakes of others are good teachers'. Proverb.

                        Comment

                        • Alvin Bruney

                          #27
                          Re: Thread.Sleep...

                          It's all good. No hard feelings.

                          --


                          -----------
                          Got TidBits?
                          Get it here: www.networkip.net/tidbits
                          <Curious> wrote in message news:3fa625ac.2 37560671@news.m icrosoft.com...[color=blue]
                          >
                          > Yo.
                          >
                          > Ahhh, well in that case it seems that indeed I was in the wrong. I
                          > guess it was one of those days and I needed to get some steam out.
                          >
                          > Having read some of your earlier posts and then reading "your" reply
                          > to:
                          >
                          > NGEN microsoft system dlls? by Bob Whiton in
                          > microsoft.publi c.dotnet.perfor mance
                          >
                          > I thought hang on, that's a bit out of order.
                          >
                          > Again, appologies for jumping the gun there - never meant to upset you
                          > in any way. I would feel bad if I did annoy you.
                          >
                          > All the best dude.
                          >
                          > 'The mistakes of others are good teachers'. Proverb.[/color]


                          Comment

                          Working...