Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need the share scheduling operating system service for real time application algorithm in c++ code. is there any one can help me ?
Posted
Comments
TRK3 22-Feb-12 18:24pm    
It's not clear what you are asking.

It sounds like you are writing a scheduler for a real-time operating system. Is that correct?

Is this a homework assignment?

It's quite rare that anybody writes there own OS, unless you are building one for a small embedded system -- even then there are open source or proprietary options that are probably a better bet than writing it yourself.

1 solution

I think you are required to write the context switch function for your imagined RTOS. (The context switch or the task scheduler is the function in the RTOS which decides which task should be scheduled).

I assume there are no priorities and that there is no need to give more CPU time to higher priority tasks.

As you want it written in C/C++, to achieve your requirement, the scheduler should have a table of function pointers to all task's entry points, and also run-time data (array) on CPU time that each task consumed so far. We will call it "CPU tick counter", and you will have one per each task.

The first part of the assignment is to schedule the correct task (the one that so far has had less CPU time than others, to ensure fairness)

Simplistically, you would find the lowest CPU tick counter in the array and schedule that task (call it via a function pointer).

The second part of the task is to correctly maintain the task's tick counters. To do it accurately, you need to measure this under a fixed timer interrupt control. Inside the interrupt routine, you will identify which task is currently running, and increment the tick counter for that task. If this is a homework assignment, you can simply allude to the fact that this will be required and may get away with it without writing the actual code for it.

And finally, you want to do some housekeeping - and prevent the tick counters from overflowing. Simplistically, you can subtract the the lowest value from CPU tick counters of all tasks, the best time to do this is just before you schedule the task. Of course, in this case the task which will be scheduled will have the tick counter of 0 which is kind-of neat. If you do this correctly, an A+ grade is almost guaranteed.

Cheers
 
Share this answer
 
v4
Comments
b.eshraghi 8-Apr-12 11:18am    
hi, thank you for your answer, it was complete, but I have to implement it as soon as possible and really I don't know how It could be possible ?
could I ask you to help me?
michaelmel 9-Apr-12 20:44pm    
I doubt anyone will be prepared to actually write it for you as it would defeat the purpose of the assignment. I think I have pointed you in the right direction.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900