views:

315

answers:

2

Hi,

I need to suspend the current thread if there exists a high priority thread, How can I do that.I need to suspend that thread and execute the new high priority thread first then after it accomplished, then resume earlier one.

+1  A: 

http://stackoverflow.com/questions/1916792/how-can-i-stop-a-thread-in-c/1916857#1916857

you are confusing the concept of "thread", and "opperation" what you want is to sync opperations...

nice source on threading:

http://www.albahari.com/threading/

Hellfrost
+1  A: 

I need to suspend the current thread if there exists a high priority thread

That's not how threads work. They're supposed to run in parallel, with high priority threads given more time - the OS does that automatically for you. You shouldn't try to interfere with that, especially since nowadays most computers have multiple cores and giving one thread absolute priority won't even make it execute faster.

Michael Borgwardt
that's fine. But I want to make lower priority thread to wait or suspend for a time and High priority thread execute at once. So it looks faster
marshalprince
No, you don't want that, because it will not work any better than assigning priorities correctly, but will make everything slower on multicore machines, i.e. all modern PCs.
Michael Borgwardt
then if highest priority thread is started, and I want to execute that faster I can not suspend the lower priority one?
marshalprince
Even if you could, it is not likely to make the other one go any faster. First, they may be running on different cores, Second, any modern OS has dozens of processes running in the background; the effect of your low priority thread is going to be lost in the noise.
Michael Borgwardt