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. How to temporarily pause all threads except one

How to temporarily pause all threads except one

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 Posts 3 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.
  • G Offline
    G Offline
    GameProfessor
    wrote on last edited by
    #1

    hi, I have a multithreaded program. In one thread, I have a very important section. I want to put all other thread to sleep when this thread comes to this section. Is there anyway to do this? The data in this section is accessed from many many places so it's almost impossible to use CCriticalSection to lock it. thanks for any help.

    L S 2 Replies Last reply
    0
    • G GameProfessor

      hi, I have a multithreaded program. In one thread, I have a very important section. I want to put all other thread to sleep when this thread comes to this section. Is there anyway to do this? The data in this section is accessed from many many places so it's almost impossible to use CCriticalSection to lock it. thanks for any help.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You'd be much better off putting in the effort to hide this data behind some interface with locking built in than try to put all the other threads to sleep. Im sure you can find api's to enumerate the threads in your program and pause each of them but I think that would be very dangerous

      1 Reply Last reply
      0
      • G GameProfessor

        hi, I have a multithreaded program. In one thread, I have a very important section. I want to put all other thread to sleep when this thread comes to this section. Is there anyway to do this? The data in this section is accessed from many many places so it's almost impossible to use CCriticalSection to lock it. thanks for any help.

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        GameProfessor wrote:

        hi, I have a multithreaded program. In one thread, I have a very important section. I want to put all other thread to sleep when this thread comes to this section. Is there anyway to do this? The data in this section is accessed from many many places so it's almost impossible to use CCriticalSection to lock it.

        This is a bad design and is asking for trouble. My advice would be "don't go there". Apart from the pitfalls[^] of putting threads to "sleep", how can you be sure one of the threads hasn't been interrupted in the middle of an update operation to the shared data and left it in an invalid state?

        Steve

        G 1 Reply Last reply
        0
        • S Stephen Hewitt

          GameProfessor wrote:

          hi, I have a multithreaded program. In one thread, I have a very important section. I want to put all other thread to sleep when this thread comes to this section. Is there anyway to do this? The data in this section is accessed from many many places so it's almost impossible to use CCriticalSection to lock it.

          This is a bad design and is asking for trouble. My advice would be "don't go there". Apart from the pitfalls[^] of putting threads to "sleep", how can you be sure one of the threads hasn't been interrupted in the middle of an update operation to the shared data and left it in an invalid state?

          Steve

          G Offline
          G Offline
          GameProfessor
          wrote on last edited by
          #4

          thanks, although your comment make me creepy ::(( I think I'll try Josh Gray's advice: trying to build a interface to lock my section. It could be difficult but it seems worthy to try.

          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