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 / C++ / MFC
  4. Stoping thread....

Stoping thread....

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 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.
  • N Offline
    N Offline
    neha agarwal27
    wrote on last edited by
    #1

    Hi All, I have made a worker thread in which i have defined a critical section using CCriticalSection class. I have started this worker thread inside a for loop. Now my problem is when i want to stop my thread before completing the for loop(ie i want that all the threads already running should stop as well as no new thread should start). I am not getting the way to do this. Can anybody help me in this. Thanks in advance.

    C S D 3 Replies Last reply
    0
    • N neha agarwal27

      Hi All, I have made a worker thread in which i have defined a critical section using CCriticalSection class. I have started this worker thread inside a for loop. Now my problem is when i want to stop my thread before completing the for loop(ie i want that all the threads already running should stop as well as no new thread should start). I am not getting the way to do this. Can anybody help me in this. Thanks in advance.

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      In general the way to do it is to use a flag to tell the thread to continue looping or not: the loop will check this flag and continue its work until it is set. Then, from your main thread, you can set this flag in order to stop the thread. But of course, this depends a lot of your current architecture.


      Cédric Moonen Software developer
      Charting control [v1.2]

      1 Reply Last reply
      0
      • N neha agarwal27

        Hi All, I have made a worker thread in which i have defined a critical section using CCriticalSection class. I have started this worker thread inside a for loop. Now my problem is when i want to stop my thread before completing the for loop(ie i want that all the threads already running should stop as well as no new thread should start). I am not getting the way to do this. Can anybody help me in this. Thanks in advance.

        S Offline
        S Offline
        Sreedhar DV
        wrote on last edited by
        #3

        Can you post the sample code snippet. Upto my understanding, set a flag before start the thread. Based on the flag start or stop your threads in the for loop.

        Sreedhar DV [Real success is having courage to meet failure without being defeated.]

        1 Reply Last reply
        0
        • N neha agarwal27

          Hi All, I have made a worker thread in which i have defined a critical section using CCriticalSection class. I have started this worker thread inside a for loop. Now my problem is when i want to stop my thread before completing the for loop(ie i want that all the threads already running should stop as well as no new thread should start). I am not getting the way to do this. Can anybody help me in this. Thanks in advance.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          See here for thread shutdown discussions.


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          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