You are here:

C++/MULTITHREADINDING PRIORITY IN VC++

Advertisement


Question
  Hi Bill, I am working VC++ 6.0 platform. For my application I needed multithreaded concept implementation. I included three threads for example
1.Thread1_Acquisition
2.Thread2_Processing
3.Thread3_Ejection.

I want to give priority to different threads. If I give THREAD_PRIORITY_NORMAL  or THREAD_PRIORITY_ABOVE_NORMAL  to all the threads my application is working correctly. But if I give higher priority to Thread1_Acquisition the application is not working exactly what I expect. What is the reason behind this? I need to give highest priority to Thread1_Acquisition, Second priority to Thread3_Ejection and lowest priority to Thread2_Processing in my application.

  Even if higher priority(THREAD_PRIORITY_ABOVE_NORMAL) is given to Thread2_Processing , the application is working correctly. And also if  higher priority(THREAD_PRIORITY_ABOVE_NORMAL)is given to Thread2_Processing and
Thread3_Ejection , the application is working correctly. Can u send me the better solution for this problem . I am waiting for your reply.  

Answer
Hi,

If Thread1_Acquisition doesn't yield or give up processor time, then it will take much more time than the other 2 threads possibly causing odd behavior.  Are there times that Thread1_Acquisition can lower its priority - like if it does an aquisition, there has to be time before it does another one.  This would be a good time to lower the priority.

When I looked at thread priorities years ago, I recall reading that changing them can cause erratic behavior.  I think the intent is to give processes different priorities by the setting the threads in them the same.  This is the mechanism for having background programs that use very little processor time.

What is the problem of running all 3 threads the same?

Bill

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill A

Expertise

I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.

Experience

I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Publications
Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

Education/Credentials
BS Computer Engineering

©2016 About.com. All rights reserved.