Task scheulder of two queues

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ZigZogZang
Posts: 14
Joined: Tue Nov 26, 2013 7:41 am

Task scheulder of two queues

Post 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 ?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Task scheulder of two queues

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
ZigZogZang
Posts: 14
Joined: Tue Nov 26, 2013 7:41 am

Re: Task scheulder of two queues

Post 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?
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Task scheulder of two queues

Post 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.
Post Reply