0

For the sake of argument i'm trying to define an algorithm that creates a pool of tasks (each task has an individual time-slice to operate) and managing them without the system clock.

The problem that i've encountered is that with each approach that I was taking, the tasks with the higher time-slice were starved.

What i've tried to do is creating a tasks vector that contains a pair of task/(int) "time". I've sorted the vector with the lowest "time" first & then iterated and executed each task with a time of zero (0). While iterating through the entire vector i've decreased the "time" of each task.

Is there a better approach to this kind of "problem". With my approach, startvation definitely will occur.

Erez
  • 37
  • 1
  • 8
  • What is the definition of the value of "time"? How is it initially set for each task? Can it ever increase? – A. I. Breveleri Aug 31 '14 at 17:35
  • Let me clarify it even more: Vector = {Task1 | int time = 12, Task2 | int time = 10} So, Task2 will run first & than after 2 more "ticks" Task1 will run. For the sake of the argument I can't use the system time (clock) to priorities the tasks. – Erez Aug 31 '14 at 19:55
  • More accurate defenition: "Design a system for managing tasks without an option to use the system time (clock)" – Erez Aug 31 '14 at 19:56
  • So, where do the "ticks" come from? – A. I. Breveleri Sep 01 '14 at 01:08

1 Answers1

1

Managing tasks may not need a system clock at all. You only need to figure a way to determine the priority between each task then run each task following their priority.

You may want to pause a task to execute another task and then will need to set a new priority to the paused task. This feature (Multitasking) will need an interruption based on an event (usually clock-time, but you can use any other event like temperature or monkey pushing a button or another process sending a signal).

You say your problem is that tasks with the higher time-slice are starving. As you decrease the 'time' of each task when running it and assuming 'time' will not be negative, higher time-slice tasks will eventually get to 0 and as well as every other task.

SkyDream
  • 382
  • 1
  • 10