Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Thread.Sleep(0) action?

Thread.Sleep(0) action?

Scheduled Pinned Locked Moved C#
question
8 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bruce Coward
    wrote on last edited by
    #1

    Does Thread.Sleep(0) allow the time slicer to start the next thread straight away or does it just idle the cpu in the existing thread until the next thread is scheduled to start? Thanks, Bruce :confused:

    N 1 Reply Last reply
    0
    • B Bruce Coward

      Does Thread.Sleep(0) allow the time slicer to start the next thread straight away or does it just idle the cpu in the existing thread until the next thread is scheduled to start? Thanks, Bruce :confused:

      N Offline
      N Offline
      Nuri Ismail
      wrote on last edited by
      #2

      The answer is here[^] " Specify zero (0) to indicate that this thread should be suspended to allow other waiting threads to execute. Specify Infinite to block the thread indefinitely. "

      B 1 Reply Last reply
      0
      • N Nuri Ismail

        The answer is here[^] " Specify zero (0) to indicate that this thread should be suspended to allow other waiting threads to execute. Specify Infinite to block the thread indefinitely. "

        B Offline
        B Offline
        Bruce Coward
        wrote on last edited by
        #3

        That is how I had interpreted the MSDN info but my hardware vendor is telling me that the balance of the thread time idles the cpu before relinquishing the thread. Does anybody know if the time slicer can detect this sleep(0) to switch the time slice early?

        L 1 Reply Last reply
        0
        • B Bruce Coward

          That is how I had interpreted the MSDN info but my hardware vendor is telling me that the balance of the thread time idles the cpu before relinquishing the thread. Does anybody know if the time slicer can detect this sleep(0) to switch the time slice early?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Bruce Coward wrote:

          my hardware vendor is telling me that the balance of the thread time idles the cpu

          that is nonsense. Every Thread.Sleep tells the scheduler to go and reschedule threads, i.e. continue working on the highest-priority ready thread; if the caller happens to be the only ready thread, it will continue working immediately. A scheduler is not supposed to idle until a tick occurs, when there is work to do (i.e. there are ready threads), then at least some of it should be taken on immediately. What would be the point to halt the CPU till the end of the current tick??? I have developed my share of embedded operating systems, and used some commercial ones, I've never seen one that deliberately did nothing for a while, not even Windows. :-D :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


          modified on Sunday, June 12, 2011 8:14 AM

          P B 2 Replies Last reply
          0
          • L Luc Pattyn

            Bruce Coward wrote:

            my hardware vendor is telling me that the balance of the thread time idles the cpu

            that is nonsense. Every Thread.Sleep tells the scheduler to go and reschedule threads, i.e. continue working on the highest-priority ready thread; if the caller happens to be the only ready thread, it will continue working immediately. A scheduler is not supposed to idle until a tick occurs, when there is work to do (i.e. there are ready threads), then at least some of it should be taken on immediately. What would be the point to halt the CPU till the end of the current tick??? I have developed my share of embedded operating systems, and used some commercial ones, I've never seen one that deliberately did nothing for a while, not even Windows. :-D :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


            modified on Sunday, June 12, 2011 8:14 AM

            P Online
            P Online
            PIEBALDconsult
            wrote on last edited by
            #5

            Luc Pattyn wrote:

            I've never seen one that deliberately did nothing for a while

            What about virtually nothing? :-D

            L 1 Reply Last reply
            0
            • L Luc Pattyn

              Bruce Coward wrote:

              my hardware vendor is telling me that the balance of the thread time idles the cpu

              that is nonsense. Every Thread.Sleep tells the scheduler to go and reschedule threads, i.e. continue working on the highest-priority ready thread; if the caller happens to be the only ready thread, it will continue working immediately. A scheduler is not supposed to idle until a tick occurs, when there is work to do (i.e. there are ready threads), then at least some of it should be taken on immediately. What would be the point to halt the CPU till the end of the current tick??? I have developed my share of embedded operating systems, and used some commercial ones, I've never seen one that deliberately did nothing for a while, not even Windows. :-D :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


              modified on Sunday, June 12, 2011 8:14 AM

              B Offline
              B Offline
              Bruce Coward
              wrote on last edited by
              #6

              Hi Luc, your reply makes more sense to me. Cheers, Bruce :thumbsup:

              1 Reply Last reply
              0
              • P PIEBALDconsult

                Luc Pattyn wrote:

                I've never seen one that deliberately did nothing for a while

                What about virtually nothing? :-D

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                PIEBALDconsult wrote:

                virtually nothing?

                The future method Thread.Doze() is scheduled for introduction in .NET 4.5 :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                modified on Sunday, June 12, 2011 8:14 AM

                P 1 Reply Last reply
                0
                • L Luc Pattyn

                  PIEBALDconsult wrote:

                  virtually nothing?

                  The future method Thread.Doze() is scheduled for introduction in .NET 4.5 :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                  modified on Sunday, June 12, 2011 8:14 AM

                  P Online
                  P Online
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  I was hoping for Thread.Winks ( 40 ) ; Oh, wait, I could use an Extension Method for that... obfuscation here I come!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups