prioritizing threads
Hi all
I Am trying to do thread prioritization.I am applying SCHED_RR and SCHED_FIFO but in both the cases thread 1 is running more times than thread 2.am giving same priority to both the threads. Kindly check the code below Code:
#include <unistd.h> /* Symbolic Constants */ |
Quote:
|
We have made some changes in the code check this and
Code:
#include <unistd.h> /* Symbolic Constants */ Code:
We are running this program on target board PXA 300 with real time patch. we have run this program in normal PC as well output is coming similar to that |
Again, you have to be careful how you are measuring this.
Since both threads are tying up the output to the terminal, you won't get a lot of real task switching going on (ie, one thread will hog the resource, and the other thread will be forced to wait, otherwise known as thread starvation). Occasionally you will see a switch, but it will be rare. Over a long enough period of time, you will see both threads get a fair go. A better method is to do more work in each thread before sending anything to the output, so that the chances of both being in the output write at the same time are reduced. But even just the following test shows you that it is working. The threads will still only switch rarely, but at least the redirection will give a larger sample size). Code:
./a.out >a.txt |
When you try to "observe" the behavior of threads in this way, the very fact that you are observing them completely changes their behavior. (And... thus, invalidates your measures.)
Treat thread-prioritization only "at best, as a suggestion to the scheduler." Whenever two threads happen to be, for whatever reason, "simultaneously available for dispatching" (and at no other time...), the thread-priority value comes into play. This is your chance to say, "well, sir, all things being equal... if it's quite all right with you, sir... I would prefer that you, please sir..." And then you must leave it at that. You can never predict which thread will be dispatched "first," "next," or "more/less often." That's strictly the decision of the Scheduler, and you are obliged to assume that it really does know what it is doing. |
I have a PXA300 board in which iam running my application I am using mutex , semaphore for the proper scheduling & time optimization ,some how I have achieved the time optimization . But i want to further improvement in the timing ,
So I used scheduler (round robin & FIFO) but it seems there is no further improvement in the timing ,Do i have to change the design of my application for the further improvement of timing. or If u can suggest me something else to do in my code .I cannot post my application here since it is huge. |
It frankly seems to me that you are asking for a degree of control over "the timing" that you simply can't have.
You don't say what "improvement in the timing" would mean to you and to this application. You're going to have to be able to identify "where it hurts," and "why it hurts," and to do so in such a way that it points to an implementable solution. Remember that the operating system's thread-and-task scheduler is not a generalized "workload scheduler" such as a high-volume/high-availability application might require to have within itself. In fact, most such applications that I have seen are single-threaded. |
All times are GMT -5. The time now is 07:03 PM. |