Mutlitasking: Actually giving up the timeslice
Posted: Thu Aug 18, 2011 5:59 pm
Is it normal when two tasks are executing this code:
that they print like this (yes, I have semaphores protecting the console):
11111111112222222222222222222111111111111111111111111222222222222222222
or should it be more like this:
1212121212121212121212121212121212121212121212121212121212121212121212121
My first thought is that they should each execute evenly, and print like the second, but then again, it all has to do with timeslices, so maybe I shouldn't make it work like that.
The title is because when a task unlocks a mutex, I originally programmed it to give up it's timeslice (since another task was just released, and needs to execute), but the way I do it is:
which is the variable holding the remaining ticks of the current timeslice, but in my code, the loop take such little time to execute that it executes like the first example because of the amount of time between timer interrupt fires.
If it is executing like it should, then there is nothing else, but if it should be executing as the second example, how could I force a task switch without artificially firing the timer interrupt (I assume you can do by just calling "int 8" since IRQ0-7 are mapped to INT8-15) ? I don't want to do that because that will effect my up-time counter; I know it's not a big deal, but I would prefer not to mess that up.
Code: Select all
void task()
{
while( 1 ) k_printf("%i", task_get_pid());
}
11111111112222222222222222222111111111111111111111111222222222222222222
or should it be more like this:
1212121212121212121212121212121212121212121212121212121212121212121212121
My first thought is that they should each execute evenly, and print like the second, but then again, it all has to do with timeslices, so maybe I shouldn't make it work like that.
The title is because when a task unlocks a mutex, I originally programmed it to give up it's timeslice (since another task was just released, and needs to execute), but the way I do it is:
Code: Select all
sched.timeslice = 0;
If it is executing like it should, then there is nothing else, but if it should be executing as the second example, how could I force a task switch without artificially firing the timer interrupt (I assume you can do by just calling "int 8" since IRQ0-7 are mapped to INT8-15) ? I don't want to do that because that will effect my up-time counter; I know it's not a big deal, but I would prefer not to mess that up.