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