Page 1 of 1

Task scheulder of two queues

Posted: Tue Nov 26, 2013 8:01 am
by ZigZogZang
Hey. Currently my OS is using round robin scheduler (1-way queue). I want to rebuild it and create 2 queues. Let's suppose first queue will have 20ms for each task inside it and tasks inside 2nd queue will get 15ms for executing.

My problem is about displaying graphics at screen. I want to make simple game "snake". I want snake to be moved in 1 direction 1 time for 1 second. When it will be put inside first queue it will be executed too many times and he will move too fast - player will be able to press key arrow fast, and i want make limit 1 press per second.

Lets say i have 4 tasks. 3 tasks in 1st queue in 1 in 2nd queue. Game's task (task1) is inside 1st queue. So until it will be executed next time it's approximately = 20ms (task2) + 20ms (task3) + 15ms (task4) = 55ms

55ms is too often

What are tricks to deal with it ?

I have found 1 simple idea to let move 1 time per second to calculate executions and allow snake to move after calculating 1000ms (1second) / 55ms = 18 ticks.

Is it correct way of doing it or may it be implemented in better sort of way ?

Re: Task scheulder of two queues

Posted: Tue Nov 26, 2013 9:18 am
by Combuster
I think you're including all the irrelevant things into the problem, making it too difficult so that you're missing the obvious.


How would you solve the problem on a fully functional platform. Like, a game loop in SDL? (or any framework you're familiar with for that matter) It's probably one of the ways to solve it in your own OS, if not the way.

Re: Task scheulder of two queues

Posted: Wed Nov 27, 2013 7:21 am
by ZigZogZang
Combuster wrote:I think you're including all the irrelevant things into the problem, making it too difficult so that you're missing the obvious.


How would you solve the problem on a fully functional platform. Like, a game loop in SDL? (or any framework you're familiar with for that matter) It's probably one of the ways to solve it in your own OS, if not the way.

How ? I have never used SDL ;p

Seems to be simple but i don't see it ;)

Hmm?

Re: Task scheulder of two queues

Posted: Wed Nov 27, 2013 8:33 am
by bluemoon
You should implement some sort of sleep for scheduler so that you don't burn the cpu.

On the game application, you query the time and do rate control, and shouldn't care about how your game is scheduled.