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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. threading question

threading question

Scheduled Pinned Locked Moved C / C++ / MFC
designquestion
5 Posts 4 Posters 0 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
    Beer
    wrote on last edited by
    #1

    I've seen many examples of people using while (pointer->nContinue) Sleep(0); in a CWinthread function to keep a thread going, as opposed to while (pointer->nContinue) { } I noticed that the former works well, whilst the latter sucks up your CPU and prevents your ui from being repainted in a timely fashion. So my question is, what's the ideal Sleep(ms) to keep your thread in a loop. The reason this particular thread doesn't return is because it manipulates a class generated by the original thread, and starts another thread as hey

    G R N 3 Replies Last reply
    0
    • B Beer

      I've seen many examples of people using while (pointer->nContinue) Sleep(0); in a CWinthread function to keep a thread going, as opposed to while (pointer->nContinue) { } I noticed that the former works well, whilst the latter sucks up your CPU and prevents your ui from being repainted in a timely fashion. So my question is, what's the ideal Sleep(ms) to keep your thread in a loop. The reason this particular thread doesn't return is because it manipulates a class generated by the original thread, and starts another thread as hey

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      Sleep(0) releases the rest of your time-slice, and the O/S switches execution to another thread.


      Software Zen: delete this;

      B 1 Reply Last reply
      0
      • G Gary R Wheeler

        Sleep(0) releases the rest of your time-slice, and the O/S switches execution to another thread.


        Software Zen: delete this;

        B Offline
        B Offline
        Beer
        wrote on last edited by
        #3

        thank you hey

        1 Reply Last reply
        0
        • B Beer

          I've seen many examples of people using while (pointer->nContinue) Sleep(0); in a CWinthread function to keep a thread going, as opposed to while (pointer->nContinue) { } I noticed that the former works well, whilst the latter sucks up your CPU and prevents your ui from being repainted in a timely fashion. So my question is, what's the ideal Sleep(ms) to keep your thread in a loop. The reason this particular thread doesn't return is because it manipulates a class generated by the original thread, and starts another thread as hey

          R Offline
          R Offline
          Renjith Ramachandran
          wrote on last edited by
          #4

          while(sleep(0) { } solves all


          [ It is possible to represent everything in this universe by using 0 and 1 ]

          1 Reply Last reply
          0
          • B Beer

            I've seen many examples of people using while (pointer->nContinue) Sleep(0); in a CWinthread function to keep a thread going, as opposed to while (pointer->nContinue) { } I noticed that the former works well, whilst the latter sucks up your CPU and prevents your ui from being repainted in a timely fashion. So my question is, what's the ideal Sleep(ms) to keep your thread in a loop. The reason this particular thread doesn't return is because it manipulates a class generated by the original thread, and starts another thread as hey

            N Offline
            N Offline
            Neville Franks
            wrote on last edited by
            #5

            If the thread has noting to do, you are better of putting into a wait state and using an Event to get it going again. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

            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